rails 4.0.13 → 4.1.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -17
- data/guides/CHANGELOG.md +68 -34
- data/guides/assets/images/edge_badge.png +0 -0
- data/guides/assets/images/feature_tile.gif +0 -0
- data/guides/assets/images/footer_tile.gif +0 -0
- data/guides/assets/images/fxn.png +0 -0
- data/guides/assets/images/getting_started/article_with_comments.png +0 -0
- data/guides/assets/images/getting_started/challenge.png +0 -0
- data/guides/assets/images/getting_started/confirm_dialog.png +0 -0
- data/guides/assets/images/getting_started/forbidden_attributes_for_new_article.png +0 -0
- data/guides/assets/images/getting_started/form_with_errors.png +0 -0
- data/guides/assets/images/getting_started/index_action_with_edit_link.png +0 -0
- data/guides/assets/images/getting_started/new_article.png +0 -0
- data/guides/assets/images/getting_started/rails_welcome.png +0 -0
- data/guides/assets/images/getting_started/routing_error_no_controller.png +0 -0
- data/guides/assets/images/getting_started/routing_error_no_route_matches.png +0 -0
- data/guides/assets/images/getting_started/show_action_for_articles.png +0 -0
- data/guides/assets/images/getting_started/template_is_missing_articles_new.png +0 -0
- data/guides/assets/images/getting_started/unknown_action_create_for_articles.png +0 -0
- data/guides/assets/images/getting_started/unknown_action_new_for_articles.png +0 -0
- data/guides/assets/images/header_tile.gif +0 -0
- data/guides/assets/images/icons/README +1 -1
- data/guides/assets/images/icons/callouts/11.png +0 -0
- data/guides/assets/images/icons/callouts/12.png +0 -0
- data/guides/assets/images/icons/callouts/13.png +0 -0
- data/guides/assets/images/icons/callouts/15.png +0 -0
- data/guides/assets/images/icons/caution.png +0 -0
- data/guides/assets/images/icons/example.png +0 -0
- data/guides/assets/images/radar.png +0 -0
- data/guides/assets/images/rails4_features.png +0 -0
- data/guides/assets/images/rails_guides_kindle_cover.jpg +0 -0
- data/guides/assets/images/vijaydev.jpg +0 -0
- data/guides/assets/javascripts/guides.js +30 -34
- data/guides/assets/stylesheets/main.css +2 -1
- data/guides/assets/stylesheets/print.css +1 -1
- data/guides/bug_report_templates/action_controller_gem.rb +9 -4
- data/guides/bug_report_templates/action_controller_master.rb +4 -2
- data/guides/bug_report_templates/active_record_gem.rb +5 -2
- data/guides/bug_report_templates/active_record_master.rb +2 -1
- data/guides/bug_report_templates/generic_gem.rb +15 -0
- data/guides/bug_report_templates/generic_master.rb +26 -0
- data/guides/code/getting_started/Gemfile +21 -24
- data/guides/code/getting_started/Gemfile.lock +78 -73
- data/guides/code/getting_started/Rakefile +1 -1
- data/guides/code/getting_started/app/assets/javascripts/application.js +1 -2
- data/guides/code/getting_started/app/views/layouts/application.html.erb +2 -2
- data/guides/code/getting_started/config/environment.rb +1 -1
- data/guides/code/getting_started/config/environments/development.rb +2 -2
- data/guides/code/getting_started/config/environments/production.rb +3 -3
- data/guides/code/getting_started/config/environments/test.rb +2 -2
- data/guides/code/getting_started/config/initializers/secret_token.rb +1 -1
- data/guides/code/getting_started/config/initializers/session_store.rb +1 -1
- data/guides/code/getting_started/config/routes.rb +1 -1
- data/guides/code/getting_started/config.ru +1 -1
- data/guides/code/getting_started/public/404.html +2 -0
- data/guides/code/getting_started/public/422.html +2 -0
- data/guides/code/getting_started/public/500.html +2 -0
- data/guides/code/getting_started/test/test_helper.rb +0 -3
- data/guides/rails_guides/helpers.rb +3 -1
- data/guides/source/2_2_release_notes.md +2 -2
- data/guides/source/2_3_release_notes.md +8 -8
- data/guides/source/3_0_release_notes.md +2 -3
- data/guides/source/3_1_release_notes.md +2 -2
- data/guides/source/3_2_release_notes.md +12 -12
- data/guides/source/4_0_release_notes.md +79 -46
- data/guides/source/4_1_release_notes.md +731 -0
- data/guides/source/_welcome.html.erb +5 -2
- data/guides/source/action_controller_overview.md +189 -40
- data/guides/source/action_mailer_basics.md +27 -27
- data/guides/source/action_view_overview.md +131 -20
- data/guides/source/active_model_basics.md +6 -6
- data/guides/source/active_record_basics.md +15 -15
- data/guides/source/active_record_callbacks.md +18 -16
- data/guides/source/active_record_querying.md +93 -51
- data/guides/source/active_record_validations.md +26 -24
- data/guides/source/active_support_core_extensions.md +72 -118
- data/guides/source/active_support_instrumentation.md +13 -4
- data/guides/source/api_documentation_guidelines.md +104 -6
- data/guides/source/asset_pipeline.md +573 -244
- data/guides/source/association_basics.md +94 -22
- data/guides/source/caching_with_rails.md +15 -6
- data/guides/source/command_line.md +55 -46
- data/guides/source/configuring.md +248 -52
- data/guides/source/contributing_to_ruby_on_rails.md +18 -17
- data/guides/source/credits.html.erb +2 -2
- data/guides/source/debugging_rails_applications.md +39 -8
- data/guides/source/development_dependencies_install.md +91 -8
- data/guides/source/documents.yaml +4 -0
- data/guides/source/engines.md +678 -232
- data/guides/source/form_helpers.md +53 -35
- data/guides/source/generators.md +19 -15
- data/guides/source/getting_started.md +758 -497
- data/guides/source/i18n.md +64 -28
- data/guides/source/index.html.erb +1 -1
- data/guides/source/initialization.md +155 -58
- data/guides/source/kindle/toc.html.erb +1 -1
- data/guides/source/layout.html.erb +2 -2
- data/guides/source/layouts_and_rendering.md +59 -26
- data/guides/source/maintenance_policy.md +3 -3
- data/guides/source/migrations.md +101 -62
- data/guides/source/nested_model_forms.md +3 -3
- data/guides/source/plugins.md +34 -31
- data/guides/source/rails_application_templates.md +27 -8
- data/guides/source/rails_on_rack.md +41 -58
- data/guides/source/routing.md +115 -104
- data/guides/source/ruby_on_rails_guides_guidelines.md +2 -2
- data/guides/source/security.md +81 -36
- data/guides/source/testing.md +56 -79
- data/guides/source/upgrading_ruby_on_rails.md +531 -21
- data/guides/source/working_with_javascript_in_rails.md +19 -11
- metadata +51 -23
- data/guides/assets/images/getting_started/forbidden_attributes_for_new_post.png +0 -0
- data/guides/assets/images/getting_started/new_post.png +0 -0
- data/guides/assets/images/getting_started/post_with_comments.png +0 -0
- data/guides/assets/images/getting_started/show_action_for_posts.png +0 -0
- data/guides/assets/images/getting_started/template_is_missing_posts_new.png +0 -0
- data/guides/assets/images/getting_started/undefined_method_post_path.png +0 -0
- data/guides/assets/images/getting_started/unknown_action_create_for_posts.png +0 -0
- data/guides/assets/images/getting_started/unknown_action_new_for_posts.png +0 -0
- data/guides/assets/images/jaimeiniesta.jpg +0 -0
- data/guides/source/kindle/KINDLE.md +0 -26
data/guides/source/routing.md
CHANGED
@@ -36,7 +36,7 @@ the request is dispatched to the `patients` controller's `show` action with `{ i
|
|
36
36
|
|
37
37
|
### Generating Paths and URLs from Code
|
38
38
|
|
39
|
-
You can also generate paths and URLs.
|
39
|
+
You can also generate paths and URLs. If the route above is modified to be:
|
40
40
|
|
41
41
|
```ruby
|
42
42
|
get '/patients/:id', to: 'patients#show', as: 'patient'
|
@@ -89,15 +89,15 @@ resources :photos
|
|
89
89
|
|
90
90
|
creates seven different routes in your application, all mapping to the `Photos` controller:
|
91
91
|
|
92
|
-
| HTTP Verb | Path | Action
|
93
|
-
| --------- | ---------------- |
|
94
|
-
| GET | /photos | index
|
95
|
-
| GET | /photos/new | new
|
96
|
-
| POST | /photos | create
|
97
|
-
| GET | /photos/:id | show
|
98
|
-
| GET | /photos/:id/edit | edit
|
99
|
-
| PATCH/PUT | /photos/:id | update
|
100
|
-
| DELETE | /photos/:id | destroy
|
92
|
+
| HTTP Verb | Path | Controller#Action | Used for |
|
93
|
+
| --------- | ---------------- | ----------------- | -------------------------------------------- |
|
94
|
+
| GET | /photos | photos#index | display a list of all photos |
|
95
|
+
| GET | /photos/new | photos#new | return an HTML form for creating a new photo |
|
96
|
+
| POST | /photos | photos#create | create a new photo |
|
97
|
+
| GET | /photos/:id | photos#show | display a specific photo |
|
98
|
+
| GET | /photos/:id/edit | photos#edit | return an HTML form for editing a photo |
|
99
|
+
| PATCH/PUT | /photos/:id | photos#update | update a specific photo |
|
100
|
+
| DELETE | /photos/:id | photos#destroy | delete a specific photo |
|
101
101
|
|
102
102
|
NOTE: Because the router uses the HTTP verb and URL to match inbound requests, four URLs map to seven different actions.
|
103
103
|
|
@@ -138,7 +138,7 @@ Sometimes, you have a resource that clients always look up without referencing a
|
|
138
138
|
get 'profile', to: 'users#show'
|
139
139
|
```
|
140
140
|
|
141
|
-
Passing a `String` to `
|
141
|
+
Passing a `String` to `get` will expect a `controller#action` format, while passing a `Symbol` will map directly to an action:
|
142
142
|
|
143
143
|
```ruby
|
144
144
|
get 'profile', to: :show
|
@@ -152,14 +152,14 @@ resource :geocoder
|
|
152
152
|
|
153
153
|
creates six different routes in your application, all mapping to the `Geocoders` controller:
|
154
154
|
|
155
|
-
| HTTP Verb | Path | Action
|
156
|
-
| --------- | -------------- |
|
157
|
-
| GET | /geocoder/new | new | return an HTML form for creating the geocoder |
|
158
|
-
| POST | /geocoder | create | create the new geocoder |
|
159
|
-
| GET | /geocoder | show | display the one and only geocoder resource |
|
160
|
-
| GET | /geocoder/edit | edit | return an HTML form for editing the geocoder |
|
161
|
-
| PATCH/PUT | /geocoder | update | update the one and only geocoder resource |
|
162
|
-
| DELETE | /geocoder | destroy | delete the geocoder resource |
|
155
|
+
| HTTP Verb | Path | Controller#Action | Used for |
|
156
|
+
| --------- | -------------- | ----------------- | --------------------------------------------- |
|
157
|
+
| GET | /geocoder/new | geocoders#new | return an HTML form for creating the geocoder |
|
158
|
+
| POST | /geocoder | geocoders#create | create the new geocoder |
|
159
|
+
| GET | /geocoder | geocoders#show | display the one and only geocoder resource |
|
160
|
+
| GET | /geocoder/edit | geocoders#edit | return an HTML form for editing the geocoder |
|
161
|
+
| PATCH/PUT | /geocoder | geocoders#update | update the one and only geocoder resource |
|
162
|
+
| DELETE | /geocoder | geocoders#destroy | delete the geocoder resource |
|
163
163
|
|
164
164
|
NOTE: Because you might want to use the same controller for a singular route (`/account`) and a plural route (`/accounts/45`), singular resources map to plural controllers. So that, for example, `resource :photo` and `resources :photos` creates both singular and plural routes that map to the same controller (`PhotosController`).
|
165
165
|
|
@@ -171,6 +171,12 @@ A singular resourceful route generates these helpers:
|
|
171
171
|
|
172
172
|
As with plural resources, the same helpers ending in `_url` will also include the host, port and path prefix.
|
173
173
|
|
174
|
+
WARNING: A [long-standing bug](https://github.com/rails/rails/issues/1769) prevents `form_for` from working automatically with singular resources. As a workaround, specify the URL for the form directly, like so:
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
form_for @geocoder, url: geocoder_path do |f|
|
178
|
+
```
|
179
|
+
|
174
180
|
### Controller Namespaces and Routing
|
175
181
|
|
176
182
|
You may wish to organize groups of controllers under a namespace. Most commonly, you might group a number of administrative controllers under an `Admin::` namespace. You would place these controllers under the `app/controllers/admin` directory, and you can group them together in your router:
|
@@ -183,15 +189,15 @@ end
|
|
183
189
|
|
184
190
|
This will create a number of routes for each of the `posts` and `comments` controller. For `Admin::PostsController`, Rails will create:
|
185
191
|
|
186
|
-
| HTTP Verb | Path | Action
|
187
|
-
| --------- | --------------------- |
|
188
|
-
| GET | /admin/posts | index | admin_posts_path |
|
189
|
-
| GET | /admin/posts/new | new | new_admin_post_path |
|
190
|
-
| POST | /admin/posts | create | admin_posts_path |
|
191
|
-
| GET | /admin/posts/:id | show | admin_post_path(:id) |
|
192
|
-
| GET | /admin/posts/:id/edit | edit | edit_admin_post_path(:id) |
|
193
|
-
| PATCH/PUT | /admin/posts/:id | update | admin_post_path(:id) |
|
194
|
-
| DELETE | /admin/posts/:id | destroy | admin_post_path(:id) |
|
192
|
+
| HTTP Verb | Path | Controller#Action | Named Helper |
|
193
|
+
| --------- | --------------------- | ------------------- | ------------------------- |
|
194
|
+
| GET | /admin/posts | admin/posts#index | admin_posts_path |
|
195
|
+
| GET | /admin/posts/new | admin/posts#new | new_admin_post_path |
|
196
|
+
| POST | /admin/posts | admin/posts#create | admin_posts_path |
|
197
|
+
| GET | /admin/posts/:id | admin/posts#show | admin_post_path(:id) |
|
198
|
+
| GET | /admin/posts/:id/edit | admin/posts#edit | edit_admin_post_path(:id) |
|
199
|
+
| PATCH/PUT | /admin/posts/:id | admin/posts#update | admin_post_path(:id) |
|
200
|
+
| DELETE | /admin/posts/:id | admin/posts#destroy | admin_post_path(:id) |
|
195
201
|
|
196
202
|
If you want to route `/posts` (without the prefix `/admin`) to `Admin::PostsController`, you could use:
|
197
203
|
|
@@ -223,15 +229,17 @@ resources :posts, path: '/admin/posts'
|
|
223
229
|
|
224
230
|
In each of these cases, the named routes remain the same as if you did not use `scope`. In the last case, the following paths map to `PostsController`:
|
225
231
|
|
226
|
-
| HTTP Verb | Path | Action
|
227
|
-
| --------- | --------------------- |
|
228
|
-
| GET | /admin/posts | index
|
229
|
-
| GET | /admin/posts/new | new
|
230
|
-
| POST | /admin/posts | create
|
231
|
-
| GET | /admin/posts/:id | show
|
232
|
-
| GET | /admin/posts/:id/edit | edit
|
233
|
-
| PATCH/PUT | /admin/posts/:id | update
|
234
|
-
| DELETE | /admin/posts/:id | destroy
|
232
|
+
| HTTP Verb | Path | Controller#Action | Named Helper |
|
233
|
+
| --------- | --------------------- | ----------------- | ------------------- |
|
234
|
+
| GET | /admin/posts | posts#index | posts_path |
|
235
|
+
| GET | /admin/posts/new | posts#new | new_post_path |
|
236
|
+
| POST | /admin/posts | posts#create | posts_path |
|
237
|
+
| GET | /admin/posts/:id | posts#show | post_path(:id) |
|
238
|
+
| GET | /admin/posts/:id/edit | posts#edit | edit_post_path(:id) |
|
239
|
+
| PATCH/PUT | /admin/posts/:id | posts#update | post_path(:id) |
|
240
|
+
| DELETE | /admin/posts/:id | posts#destroy | post_path(:id) |
|
241
|
+
|
242
|
+
TIP: _If you need to use a different controller namespace inside a `namespace` block you can specify an absolute controller path, e.g: `get '/foo' => '/foo#index'`._
|
235
243
|
|
236
244
|
### Nested Resources
|
237
245
|
|
@@ -257,15 +265,15 @@ end
|
|
257
265
|
|
258
266
|
In addition to the routes for magazines, this declaration will also route ads to an `AdsController`. The ad URLs require a magazine:
|
259
267
|
|
260
|
-
| HTTP Verb | Path | Action
|
261
|
-
| --------- | ------------------------------------ |
|
262
|
-
| GET | /magazines/:magazine_id/ads | index
|
263
|
-
| GET | /magazines/:magazine_id/ads/new | new
|
264
|
-
| POST | /magazines/:magazine_id/ads | create
|
265
|
-
| GET | /magazines/:magazine_id/ads/:id | show
|
266
|
-
| GET | /magazines/:magazine_id/ads/:id/edit | edit
|
267
|
-
| PATCH/PUT | /magazines/:magazine_id/ads/:id | update
|
268
|
-
| DELETE | /magazines/:magazine_id/ads/:id | destroy
|
268
|
+
| HTTP Verb | Path | Controller#Action | Used for |
|
269
|
+
| --------- | ------------------------------------ | ----------------- | -------------------------------------------------------------------------- |
|
270
|
+
| GET | /magazines/:magazine_id/ads | ads#index | display a list of all ads for a specific magazine |
|
271
|
+
| GET | /magazines/:magazine_id/ads/new | ads#new | return an HTML form for creating a new ad belonging to a specific magazine |
|
272
|
+
| POST | /magazines/:magazine_id/ads | ads#create | create a new ad belonging to a specific magazine |
|
273
|
+
| GET | /magazines/:magazine_id/ads/:id | ads#show | display a specific ad belonging to a specific magazine |
|
274
|
+
| GET | /magazines/:magazine_id/ads/:id/edit | ads#edit | return an HTML form for editing an ad belonging to a specific magazine |
|
275
|
+
| PATCH/PUT | /magazines/:magazine_id/ads/:id | ads#update | update a specific ad belonging to a specific magazine |
|
276
|
+
| DELETE | /magazines/:magazine_id/ads/:id | ads#destroy | delete a specific ad belonging to a specific magazine |
|
269
277
|
|
270
278
|
This will also create routing helpers such as `magazine_ads_url` and `edit_magazine_ad_path`. These helpers take an instance of Magazine as the first parameter (`magazine_ads_url(@magazine)`).
|
271
279
|
|
@@ -332,7 +340,7 @@ shallow do
|
|
332
340
|
end
|
333
341
|
```
|
334
342
|
|
335
|
-
There
|
343
|
+
There exist two options for `scope` to customize shallow routes. `:shallow_path` prefixes member paths with the specified parameter:
|
336
344
|
|
337
345
|
```ruby
|
338
346
|
scope shallow_path: "sekret" do
|
@@ -344,15 +352,15 @@ end
|
|
344
352
|
|
345
353
|
The comments resource here will have the following routes generated for it:
|
346
354
|
|
347
|
-
| HTTP Verb | Path | Named Helper |
|
348
|
-
| --------- | -------------------------------------- | ------------------- |
|
349
|
-
| GET | /posts/:post_id/comments(.:format) | post_comments |
|
350
|
-
| POST | /posts/:post_id/comments(.:format) | post_comments |
|
351
|
-
| GET | /posts/:post_id/comments/new(.:format) | new_post_comment |
|
352
|
-
| GET | /sekret/comments/:id/edit(.:format) | edit_comment |
|
353
|
-
| GET | /sekret/comments/:id(.:format) | comment |
|
354
|
-
| PATCH/PUT | /sekret/comments/:id(.:format) | comment |
|
355
|
-
| DELETE | /sekret/comments/:id(.:format) | comment |
|
355
|
+
| HTTP Verb | Path | Controller#Action | Named Helper |
|
356
|
+
| --------- | -------------------------------------- | ----------------- | ------------------- |
|
357
|
+
| GET | /posts/:post_id/comments(.:format) | comments#index | post_comments |
|
358
|
+
| POST | /posts/:post_id/comments(.:format) | comments#create | post_comments |
|
359
|
+
| GET | /posts/:post_id/comments/new(.:format) | comments#new | new_post_comment |
|
360
|
+
| GET | /sekret/comments/:id/edit(.:format) | comments#edit | edit_comment |
|
361
|
+
| GET | /sekret/comments/:id(.:format) | comments#show | comment |
|
362
|
+
| PATCH/PUT | /sekret/comments/:id(.:format) | comments#update | comment |
|
363
|
+
| DELETE | /sekret/comments/:id(.:format) | comments#destroy | comment |
|
356
364
|
|
357
365
|
The `:shallow_prefix` option adds the specified parameter to the named helpers:
|
358
366
|
|
@@ -366,19 +374,19 @@ end
|
|
366
374
|
|
367
375
|
The comments resource here will have the following routes generated for it:
|
368
376
|
|
369
|
-
| HTTP Verb | Path | Named Helper |
|
370
|
-
| --------- | -------------------------------------- | ------------------- |
|
371
|
-
| GET | /posts/:post_id/comments(.:format) | post_comments |
|
372
|
-
| POST | /posts/:post_id/comments(.:format) | post_comments |
|
373
|
-
| GET | /posts/:post_id/comments/new(.:format) | new_post_comment |
|
374
|
-
| GET | /comments/:id/edit(.:format) | edit_sekret_comment |
|
375
|
-
| GET | /comments/:id(.:format) | sekret_comment |
|
376
|
-
| PATCH/PUT | /comments/:id(.:format) | sekret_comment |
|
377
|
-
| DELETE | /comments/:id(.:format) | sekret_comment |
|
377
|
+
| HTTP Verb | Path | Controller#Action | Named Helper |
|
378
|
+
| --------- | -------------------------------------- | ----------------- | ------------------- |
|
379
|
+
| GET | /posts/:post_id/comments(.:format) | comments#index | post_comments |
|
380
|
+
| POST | /posts/:post_id/comments(.:format) | comments#create | post_comments |
|
381
|
+
| GET | /posts/:post_id/comments/new(.:format) | comments#new | new_post_comment |
|
382
|
+
| GET | /comments/:id/edit(.:format) | comments#edit | edit_sekret_comment |
|
383
|
+
| GET | /comments/:id(.:format) | comments#show | sekret_comment |
|
384
|
+
| PATCH/PUT | /comments/:id(.:format) | comments#update | sekret_comment |
|
385
|
+
| DELETE | /comments/:id(.:format) | comments#destroy | sekret_comment |
|
378
386
|
|
379
387
|
### Routing concerns
|
380
388
|
|
381
|
-
Routing Concerns allows you to declare common routes that can be reused inside
|
389
|
+
Routing Concerns allows you to declare common routes that can be reused inside other resources and routes. To define a concern:
|
382
390
|
|
383
391
|
```ruby
|
384
392
|
concern :commentable do
|
@@ -479,7 +487,10 @@ end
|
|
479
487
|
|
480
488
|
This will recognize `/photos/1/preview` with GET, and route to the `preview` action of `PhotosController`, with the resource id value passed in `params[:id]`. It will also create the `preview_photo_url` and `preview_photo_path` helpers.
|
481
489
|
|
482
|
-
Within the block of member routes, each route name specifies the HTTP verb
|
490
|
+
Within the block of member routes, each route name specifies the HTTP verb
|
491
|
+
will be recognized. You can use `get`, `patch`, `put`, `post`, or `delete` here
|
492
|
+
. If you don't have multiple `member` routes, you can also pass `:on` to a
|
493
|
+
route, eliminating the block:
|
483
494
|
|
484
495
|
```ruby
|
485
496
|
resources :photos do
|
@@ -620,7 +631,7 @@ This will define a `user_path` method that will be available in controllers, hel
|
|
620
631
|
|
621
632
|
### HTTP Verb Constraints
|
622
633
|
|
623
|
-
In general, you should use the `get`, `post`, `put`
|
634
|
+
In general, you should use the `get`, `post`, `put`, `patch` and `delete` methods to constrain a route to a particular verb. You can use the `match` method with the `:via` option to match multiple verbs at once:
|
624
635
|
|
625
636
|
```ruby
|
626
637
|
match 'photos', to: 'photos#show', via: [:get, :post]
|
@@ -698,7 +709,7 @@ class BlacklistConstraint
|
|
698
709
|
end
|
699
710
|
end
|
700
711
|
|
701
|
-
|
712
|
+
Rails.application.routes.draw do
|
702
713
|
get '*path', to: 'blacklist#index',
|
703
714
|
constraints: BlacklistConstraint.new
|
704
715
|
end
|
@@ -707,7 +718,7 @@ end
|
|
707
718
|
You can also specify constraints as a lambda:
|
708
719
|
|
709
720
|
```ruby
|
710
|
-
|
721
|
+
Rails.application.routes.draw do
|
711
722
|
get '*path', to: 'blacklist#index',
|
712
723
|
constraints: lambda { |request| Blacklist.retrieve_ips.include?(request.remote_ip) }
|
713
724
|
end
|
@@ -767,11 +778,11 @@ You can also reuse dynamic segments from the match in the path to redirect to:
|
|
767
778
|
get '/stories/:name', to: redirect('/posts/%{name}')
|
768
779
|
```
|
769
780
|
|
770
|
-
You can also provide a block to redirect, which receives the
|
781
|
+
You can also provide a block to redirect, which receives the symbolized path parameters and the request object:
|
771
782
|
|
772
783
|
```ruby
|
773
|
-
get '/stories/:name', to: redirect {|
|
774
|
-
get '/stories', to: redirect {|
|
784
|
+
get '/stories/:name', to: redirect {|path_params, req| "/posts/#{path_params[:name].pluralize}" }
|
785
|
+
get '/stories', to: redirect {|path_params, req| "/posts/#{req.subdomain}" }
|
775
786
|
```
|
776
787
|
|
777
788
|
Please note that this redirection is a 301 "Moved Permanently" redirect. Keep in mind that some web browsers or proxy servers will cache this type of redirect, making the old page inaccessible.
|
@@ -803,7 +814,7 @@ You should put the `root` route at the top of the file, because it is the most p
|
|
803
814
|
|
804
815
|
NOTE: The `root` route only routes `GET` requests to the action.
|
805
816
|
|
806
|
-
You can also use root inside namespaces and scopes as well.
|
817
|
+
You can also use root inside namespaces and scopes as well. For example:
|
807
818
|
|
808
819
|
```ruby
|
809
820
|
namespace :admin do
|
@@ -836,15 +847,15 @@ resources :photos, controller: 'images'
|
|
836
847
|
|
837
848
|
will recognize incoming paths beginning with `/photos` but route to the `Images` controller:
|
838
849
|
|
839
|
-
| HTTP Verb | Path | Action
|
840
|
-
| --------- | ---------------- |
|
841
|
-
| GET | /photos | index
|
842
|
-
| GET | /photos/new | new
|
843
|
-
| POST | /photos | create
|
844
|
-
| GET | /photos/:id | show
|
845
|
-
| GET | /photos/:id/edit | edit
|
846
|
-
| PATCH/PUT | /photos/:id | update
|
847
|
-
| DELETE | /photos/:id | destroy
|
850
|
+
| HTTP Verb | Path | Controller#Action | Named Helper |
|
851
|
+
| --------- | ---------------- | ----------------- | -------------------- |
|
852
|
+
| GET | /photos | images#index | photos_path |
|
853
|
+
| GET | /photos/new | images#new | new_photo_path |
|
854
|
+
| POST | /photos | images#create | photos_path |
|
855
|
+
| GET | /photos/:id | images#show | photo_path(:id) |
|
856
|
+
| GET | /photos/:id/edit | images#edit | edit_photo_path(:id) |
|
857
|
+
| PATCH/PUT | /photos/:id | images#update | photo_path(:id) |
|
858
|
+
| DELETE | /photos/:id | images#destroy | photo_path(:id) |
|
848
859
|
|
849
860
|
NOTE: Use `photos_path`, `new_photo_path`, etc. to generate paths for this resource.
|
850
861
|
|
@@ -857,8 +868,8 @@ resources :user_permissions, controller: 'admin/user_permissions'
|
|
857
868
|
This will route to the `Admin::UserPermissions` controller.
|
858
869
|
|
859
870
|
NOTE: Only the directory notation is supported. Specifying the
|
860
|
-
controller with
|
861
|
-
|
871
|
+
controller with Ruby constant notation (eg. `controller: 'Admin::UserPermissions'`)
|
872
|
+
can lead to routing problems and results in
|
862
873
|
a warning.
|
863
874
|
|
864
875
|
### Specifying Constraints
|
@@ -894,15 +905,15 @@ resources :photos, as: 'images'
|
|
894
905
|
|
895
906
|
will recognize incoming paths beginning with `/photos` and route the requests to `PhotosController`, but use the value of the :as option to name the helpers.
|
896
907
|
|
897
|
-
| HTTP Verb | Path | Action
|
898
|
-
| --------- | ---------------- |
|
899
|
-
| GET | /photos | index
|
900
|
-
| GET | /photos/new | new
|
901
|
-
| POST | /photos | create
|
902
|
-
| GET | /photos/:id | show
|
903
|
-
| GET | /photos/:id/edit | edit
|
904
|
-
| PATCH/PUT | /photos/:id | update
|
905
|
-
| DELETE | /photos/:id | destroy
|
908
|
+
| HTTP Verb | Path | Controller#Action | Named Helper |
|
909
|
+
| --------- | ---------------- | ----------------- | -------------------- |
|
910
|
+
| GET | /photos | photos#index | images_path |
|
911
|
+
| GET | /photos/new | photos#new | new_image_path |
|
912
|
+
| POST | /photos | photos#create | images_path |
|
913
|
+
| GET | /photos/:id | photos#show | image_path(:id) |
|
914
|
+
| GET | /photos/:id/edit | photos#edit | edit_image_path(:id) |
|
915
|
+
| PATCH/PUT | /photos/:id | photos#update | image_path(:id) |
|
916
|
+
| DELETE | /photos/:id | photos#destroy | image_path(:id) |
|
906
917
|
|
907
918
|
### Overriding the `new` and `edit` Segments
|
908
919
|
|
@@ -999,15 +1010,15 @@ end
|
|
999
1010
|
|
1000
1011
|
Rails now creates routes to the `CategoriesController`.
|
1001
1012
|
|
1002
|
-
| HTTP Verb | Path | Action |
|
1003
|
-
| --------- | -------------------------- |
|
1004
|
-
| GET | /kategorien | index | categories_path |
|
1005
|
-
| GET | /kategorien/neu | new | new_category_path |
|
1006
|
-
| POST | /kategorien | create | categories_path |
|
1007
|
-
| GET | /kategorien/:id | show | category_path(:id) |
|
1008
|
-
| GET | /kategorien/:id/bearbeiten | edit | edit_category_path(:id) |
|
1009
|
-
| PATCH/PUT | /kategorien/:id | update | category_path(:id) |
|
1010
|
-
| DELETE | /kategorien/:id | destroy | category_path(:id) |
|
1013
|
+
| HTTP Verb | Path | Controller#Action | Named Helper |
|
1014
|
+
| --------- | -------------------------- | ------------------ | ----------------------- |
|
1015
|
+
| GET | /kategorien | categories#index | categories_path |
|
1016
|
+
| GET | /kategorien/neu | categories#new | new_category_path |
|
1017
|
+
| POST | /kategorien | categories#create | categories_path |
|
1018
|
+
| GET | /kategorien/:id | categories#show | category_path(:id) |
|
1019
|
+
| GET | /kategorien/:id/bearbeiten | categories#edit | edit_category_path(:id) |
|
1020
|
+
| PATCH/PUT | /kategorien/:id | categories#update | category_path(:id) |
|
1021
|
+
| DELETE | /kategorien/:id | categories#destroy | category_path(:id) |
|
1011
1022
|
|
1012
1023
|
### Overriding the Singular Form
|
1013
1024
|
|
@@ -1059,7 +1070,7 @@ edit_user GET /users/:id/edit(.:format) users#edit
|
|
1059
1070
|
You may restrict the listing to the routes that map to a particular controller setting the `CONTROLLER` environment variable:
|
1060
1071
|
|
1061
1072
|
```bash
|
1062
|
-
$ CONTROLLER=users rake routes
|
1073
|
+
$ CONTROLLER=users bin/rake routes
|
1063
1074
|
```
|
1064
1075
|
|
1065
1076
|
TIP: You'll find that the output from `rake routes` is much more readable if you widen your terminal window until the output lines don't wrap.
|
@@ -51,7 +51,7 @@ Use the same typography as in regular text:
|
|
51
51
|
API Documentation Guidelines
|
52
52
|
----------------------------
|
53
53
|
|
54
|
-
The guides and the API should be coherent and consistent where appropriate. Please have a look at these particular sections of the [API Documentation Guidelines](api_documentation_guidelines.html:
|
54
|
+
The guides and the API should be coherent and consistent where appropriate. Please have a look at these particular sections of the [API Documentation Guidelines](api_documentation_guidelines.html):
|
55
55
|
|
56
56
|
* [Wording](api_documentation_guidelines.html#wording)
|
57
57
|
* [Example Code](api_documentation_guidelines.html#example-code)
|
@@ -63,7 +63,7 @@ Those guidelines apply also to guides.
|
|
63
63
|
HTML Guides
|
64
64
|
-----------
|
65
65
|
|
66
|
-
Before generating the guides, make sure that you have the latest version of Bundler installed on your system. As of this writing, you must install Bundler 1.3.5 on your device.
|
66
|
+
Before generating the guides, make sure that you have the latest version of Bundler installed on your system. As of this writing, you must install Bundler 1.3.5 on your device.
|
67
67
|
|
68
68
|
To install the latest version of Bundler, simply run the `gem install bundler` command
|
69
69
|
|