rails 4.0.13 → 4.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rails might be problematic. Click here for more details.

Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -15
  3. data/guides/CHANGELOG.md +5 -74
  4. data/guides/assets/images/edge_badge.png +0 -0
  5. data/guides/assets/images/feature_tile.gif +0 -0
  6. data/guides/assets/images/footer_tile.gif +0 -0
  7. data/guides/assets/images/fxn.png +0 -0
  8. data/guides/assets/images/getting_started/challenge.png +0 -0
  9. data/guides/assets/images/getting_started/forbidden_attributes_for_new_post.png +0 -0
  10. data/guides/assets/images/getting_started/new_post.png +0 -0
  11. data/guides/assets/images/getting_started/routing_error_no_controller.png +0 -0
  12. data/guides/assets/images/getting_started/routing_error_no_route_matches.png +0 -0
  13. data/guides/assets/images/getting_started/template_is_missing_posts_new.png +0 -0
  14. data/guides/assets/images/getting_started/unknown_action_create_for_posts.png +0 -0
  15. data/guides/assets/images/getting_started/unknown_action_new_for_posts.png +0 -0
  16. data/guides/assets/images/header_tile.gif +0 -0
  17. data/guides/assets/images/icons/README +1 -1
  18. data/guides/assets/images/icons/callouts/11.png +0 -0
  19. data/guides/assets/images/icons/callouts/12.png +0 -0
  20. data/guides/assets/images/icons/callouts/13.png +0 -0
  21. data/guides/assets/images/icons/callouts/15.png +0 -0
  22. data/guides/assets/images/icons/caution.png +0 -0
  23. data/guides/assets/images/icons/example.png +0 -0
  24. data/guides/assets/images/radar.png +0 -0
  25. data/guides/assets/images/rails4_features.png +0 -0
  26. data/guides/assets/images/rails_guides_kindle_cover.jpg +0 -0
  27. data/guides/assets/images/vijaydev.jpg +0 -0
  28. data/guides/assets/javascripts/guides.js +30 -34
  29. data/guides/assets/stylesheets/main.css +2 -1
  30. data/guides/assets/stylesheets/print.css +1 -1
  31. data/guides/bug_report_templates/action_controller_gem.rb +2 -0
  32. data/guides/bug_report_templates/action_controller_master.rb +2 -0
  33. data/guides/bug_report_templates/active_record_gem.rb +1 -1
  34. data/guides/bug_report_templates/active_record_master.rb +2 -1
  35. data/guides/code/getting_started/Gemfile +1 -1
  36. data/guides/code/getting_started/app/assets/javascripts/application.js +1 -2
  37. data/guides/code/getting_started/config/environments/development.rb +1 -1
  38. data/guides/code/getting_started/public/404.html +2 -0
  39. data/guides/code/getting_started/public/422.html +2 -0
  40. data/guides/code/getting_started/public/500.html +2 -0
  41. data/guides/rails_guides/helpers.rb +1 -1
  42. data/guides/source/2_2_release_notes.md +2 -2
  43. data/guides/source/2_3_release_notes.md +8 -8
  44. data/guides/source/3_0_release_notes.md +1 -2
  45. data/guides/source/3_1_release_notes.md +1 -1
  46. data/guides/source/3_2_release_notes.md +12 -12
  47. data/guides/source/4_0_release_notes.md +79 -46
  48. data/guides/source/4_1_release_notes.md +601 -0
  49. data/guides/source/_welcome.html.erb +1 -1
  50. data/guides/source/action_controller_overview.md +117 -31
  51. data/guides/source/action_mailer_basics.md +19 -19
  52. data/guides/source/action_view_overview.md +131 -12
  53. data/guides/source/active_model_basics.md +6 -6
  54. data/guides/source/active_record_basics.md +15 -15
  55. data/guides/source/active_record_callbacks.md +18 -16
  56. data/guides/source/active_record_querying.md +67 -39
  57. data/guides/source/active_record_validations.md +31 -31
  58. data/guides/source/active_support_core_extensions.md +63 -74
  59. data/guides/source/active_support_instrumentation.md +13 -4
  60. data/guides/source/api_documentation_guidelines.md +19 -5
  61. data/guides/source/asset_pipeline.md +544 -249
  62. data/guides/source/association_basics.md +81 -22
  63. data/guides/source/caching_with_rails.md +15 -6
  64. data/guides/source/command_line.md +28 -19
  65. data/guides/source/configuring.md +98 -50
  66. data/guides/source/contributing_to_ruby_on_rails.md +11 -11
  67. data/guides/source/credits.html.erb +2 -2
  68. data/guides/source/debugging_rails_applications.md +36 -5
  69. data/guides/source/development_dependencies_install.md +89 -8
  70. data/guides/source/documents.yaml +7 -1
  71. data/guides/source/engines.md +648 -224
  72. data/guides/source/form_helpers.md +56 -45
  73. data/guides/source/generators.md +7 -3
  74. data/guides/source/getting_started.md +379 -164
  75. data/guides/source/i18n.md +59 -23
  76. data/guides/source/index.html.erb +1 -1
  77. data/guides/source/initialization.md +153 -56
  78. data/guides/source/kindle/toc.html.erb +1 -1
  79. data/guides/source/layout.html.erb +3 -3
  80. data/guides/source/layouts_and_rendering.md +12 -11
  81. data/guides/source/maintenance_policy.md +4 -23
  82. data/guides/source/migrations.md +41 -37
  83. data/guides/source/nested_model_forms.md +3 -3
  84. data/guides/source/plugins.md +27 -23
  85. data/guides/source/rails_application_templates.md +25 -6
  86. data/guides/source/rails_on_rack.md +35 -51
  87. data/guides/source/routing.md +108 -99
  88. data/guides/source/ruby_on_rails_guides_guidelines.md +2 -2
  89. data/guides/source/security.md +33 -31
  90. data/guides/source/testing.md +37 -34
  91. data/guides/source/upgrading_ruby_on_rails.md +335 -16
  92. data/guides/source/working_with_javascript_in_rails.md +18 -10
  93. metadata +66 -39
  94. data/guides/assets/images/jaimeiniesta.jpg +0 -0
  95. data/guides/source/kindle/KINDLE.md +0 -26
@@ -47,7 +47,7 @@ The following sections outline the primary methods provided by the API:
47
47
 
48
48
  ### gem(*args)
49
49
 
50
- Adds a `gem` entry for the supplied gem to the generated applications `Gemfile`.
50
+ Adds a `gem` entry for the supplied gem to the generated application's `Gemfile`.
51
51
 
52
52
  For example, if your application depends on the gems `bj` and `nokogiri`:
53
53
 
@@ -91,14 +91,14 @@ Adds a line inside the `Application` class for `config/application.rb`.
91
91
  If `options[:env]` is specified, the line is appended to the corresponding file in `config/environments`.
92
92
 
93
93
  ```ruby
94
- environment 'config.action_mailer.default_url_options = {host: 'http://yourwebsite.example.com'}, env: 'production'
94
+ environment 'config.action_mailer.default_url_options = {host: "http://yourwebsite.example.com"}', env: 'production'
95
95
  ```
96
96
 
97
97
  A block can be used in place of the `data` argument.
98
98
 
99
99
  ### vendor/lib/file/initializer(filename, data = nil, &block)
100
100
 
101
- Adds an initializer to the generated applications `config/initializers` directory.
101
+ Adds an initializer to the generated application's `config/initializers` directory.
102
102
 
103
103
  Let's say you like using `Object#not_nil?` and `Object#not_blank?`:
104
104
 
@@ -127,7 +127,7 @@ file 'app/components/foo.rb', <<-CODE
127
127
  CODE
128
128
  ```
129
129
 
130
- Thatll create the `app/components` directory and put `foo.rb` in there.
130
+ That'll create the `app/components` directory and put `foo.rb` in there.
131
131
 
132
132
  ### rakefile(filename, data = nil, &block)
133
133
 
@@ -197,7 +197,7 @@ end
197
197
 
198
198
  ### ask(question)
199
199
 
200
- `ask()` gives you a chance to get some feedback from the user and use it in your templates. Let's say you want your user to name the new shiny library youre adding:
200
+ `ask()` gives you a chance to get some feedback from the user and use it in your templates. Let's say you want your user to name the new shiny library you're adding:
201
201
 
202
202
  ```ruby
203
203
  lib_name = ask("What do you want to call the shiny library ?")
@@ -211,7 +211,7 @@ CODE
211
211
 
212
212
  ### yes?(question) or no?(question)
213
213
 
214
- These methods let you ask questions from templates and decide the flow based on the users answer. Let's say you want to freeze rails only if the user wants to:
214
+ These methods let you ask questions from templates and decide the flow based on the user's answer. Let's say you want to freeze rails only if the user wants to:
215
215
 
216
216
  ```ruby
217
217
  rake("rails:freeze:gems") if yes?("Freeze rails gems?")
@@ -227,3 +227,22 @@ git :init
227
227
  git add: "."
228
228
  git commit: "-a -m 'Initial commit'"
229
229
  ```
230
+
231
+ Advanced Usage
232
+ --------------
233
+
234
+ The application template is evaluated in the context of a
235
+ `Rails::Generators::AppGenerator` instance. It uses the `apply` action
236
+ provided by
237
+ [Thor](https://github.com/erikhuda/thor/blob/master/lib/thor/actions.rb#L207).
238
+ This means you can extend and change the instance to match your needs.
239
+
240
+ For example by overwriting the `source_paths` method to contain the
241
+ location of your template. Now methods like `copy_file` will accept
242
+ relative paths to your template's location.
243
+
244
+ ```ruby
245
+ def source_paths
246
+ [File.expand_path(File.dirname(__FILE__))]
247
+ end
248
+ ```
@@ -5,7 +5,6 @@ This guide covers Rails integration with Rack and interfacing with other Rack co
5
5
 
6
6
  After reading this guide, you will know:
7
7
 
8
- * How to create Rails Metal applications.
9
8
  * How to use Rack Middlewares in your Rails applications.
10
9
  * Action Pack's internal Middleware stack.
11
10
  * How to define a custom Middleware stack.
@@ -82,9 +81,9 @@ To use `rackup` instead of Rails' `rails server`, you can put the following insi
82
81
 
83
82
  ```ruby
84
83
  # Rails.root/config.ru
85
- require ::File.expand_path('../config/environment', __FILE__)
84
+ require ::File.expand_path('../config/environment', __FILE__)
86
85
 
87
- use Rack::Debugger
86
+ use Rails::Rack::Debugger
88
87
  use Rack::ContentLength
89
88
  run Rails.application
90
89
  ```
@@ -119,6 +118,7 @@ $ rake middleware
119
118
  For a freshly generated Rails application, this might produce something like:
120
119
 
121
120
  ```ruby
121
+ use Rack::Sendfile
122
122
  use ActionDispatch::Static
123
123
  use Rack::Lock
124
124
  use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x000000029a0838>
@@ -131,6 +131,7 @@ use ActionDispatch::DebugExceptions
131
131
  use ActionDispatch::RemoteIp
132
132
  use ActionDispatch::Reloader
133
133
  use ActionDispatch::Callbacks
134
+ use ActiveRecord::Migration::CheckPending
134
135
  use ActiveRecord::ConnectionAdapters::ConnectionManagement
135
136
  use ActiveRecord::QueryCache
136
137
  use ActionDispatch::Cookies
@@ -143,7 +144,7 @@ use Rack::ETag
143
144
  run MyApp::Application.routes
144
145
  ```
145
146
 
146
- Purpose of each of this middlewares is explained in the [Internal Middlewares](#internal-middleware-stack) section.
147
+ The default middlewares shown here (and some others) are each summarized in the [Internal Middlewares](#internal-middleware-stack) section, below.
147
148
 
148
149
  ### Configuring Middleware Stack
149
150
 
@@ -181,18 +182,17 @@ You can swap an existing middleware in the middleware stack using `config.middle
181
182
  config.middleware.swap ActionDispatch::ShowExceptions, Lifo::ShowExceptions
182
183
  ```
183
184
 
184
- #### Middleware Stack is an Enumerable
185
+ #### Deleting a Middleware
185
186
 
186
- The middleware stack behaves just like a normal `Enumerable`. You can use any `Enumerable` methods to manipulate or interrogate the stack. The middleware stack also implements some `Array` methods including `[]`, `unshift` and `delete`. Methods described in the section above are just convenience methods.
187
-
188
- Append following lines to your application configuration:
187
+ Add the following lines to your application configuration:
189
188
 
190
189
  ```ruby
191
190
  # config/application.rb
192
191
  config.middleware.delete "Rack::Lock"
193
192
  ```
194
193
 
195
- And now if you inspect the middleware stack, you'll find that `Rack::Lock` will not be part of it.
194
+ And now if you inspect the middleware stack, you'll find that `Rack::Lock` is
195
+ not a part of it.
196
196
 
197
197
  ```bash
198
198
  $ rake middleware
@@ -224,116 +224,100 @@ config.middleware.delete "Rack::MethodOverride"
224
224
 
225
225
  Much of Action Controller's functionality is implemented as Middlewares. The following list explains the purpose of each of them:
226
226
 
227
- **`Rack::Sendfile`**
227
+ **`Rack::Sendfile`**
228
228
 
229
229
  * Sets server specific X-Sendfile header. Configure this via `config.action_dispatch.x_sendfile_header` option.
230
230
 
231
- **`ActionDispatch::Static`**
231
+ **`ActionDispatch::Static`**
232
232
 
233
233
  * Used to serve static assets. Disabled if `config.serve_static_assets` is `false`.
234
234
 
235
- **`Rack::Lock`**
235
+ **`Rack::Lock`**
236
236
 
237
237
  * Sets `env["rack.multithread"]` flag to `false` and wraps the application within a Mutex.
238
238
 
239
- **`ActiveSupport::Cache::Strategy::LocalCache::Middleware`**
239
+ **`ActiveSupport::Cache::Strategy::LocalCache::Middleware`**
240
240
 
241
241
  * Used for memory caching. This cache is not thread safe.
242
242
 
243
- **`Rack::Runtime`**
243
+ **`Rack::Runtime`**
244
244
 
245
245
  * Sets an X-Runtime header, containing the time (in seconds) taken to execute the request.
246
246
 
247
- **`Rack::MethodOverride`**
247
+ **`Rack::MethodOverride`**
248
248
 
249
249
  * Allows the method to be overridden if `params[:_method]` is set. This is the middleware which supports the PUT and DELETE HTTP method types.
250
250
 
251
- **`ActionDispatch::RequestId`**
251
+ **`ActionDispatch::RequestId`**
252
252
 
253
253
  * Makes a unique `X-Request-Id` header available to the response and enables the `ActionDispatch::Request#uuid` method.
254
254
 
255
- **`Rails::Rack::Logger`**
255
+ **`Rails::Rack::Logger`**
256
256
 
257
257
  * Notifies the logs that the request has began. After request is complete, flushes all the logs.
258
258
 
259
- **`ActionDispatch::ShowExceptions`**
259
+ **`ActionDispatch::ShowExceptions`**
260
260
 
261
261
  * Rescues any exception returned by the application and calls an exceptions app that will wrap it in a format for the end user.
262
262
 
263
- **`ActionDispatch::DebugExceptions`**
263
+ **`ActionDispatch::DebugExceptions`**
264
264
 
265
265
  * Responsible for logging exceptions and showing a debugging page in case the request is local.
266
266
 
267
- **`ActionDispatch::RemoteIp`**
267
+ **`ActionDispatch::RemoteIp`**
268
268
 
269
269
  * Checks for IP spoofing attacks.
270
270
 
271
- **`ActionDispatch::Reloader`**
271
+ **`ActionDispatch::Reloader`**
272
272
 
273
273
  * Provides prepare and cleanup callbacks, intended to assist with code reloading during development.
274
274
 
275
- **`ActionDispatch::Callbacks`**
275
+ **`ActionDispatch::Callbacks`**
276
276
 
277
277
  * Runs the prepare callbacks before serving the request.
278
278
 
279
- **`ActiveRecord::ConnectionAdapters::ConnectionManagement`**
279
+ **`ActiveRecord::Migration::CheckPending`**
280
+
281
+ * Checks pending migrations and raises `ActiveRecord::PendingMigrationError` if any migrations are pending.
282
+
283
+ **`ActiveRecord::ConnectionAdapters::ConnectionManagement`**
280
284
 
281
285
  * Cleans active connections after each request, unless the `rack.test` key in the request environment is set to `true`.
282
286
 
283
- **`ActiveRecord::QueryCache`**
287
+ **`ActiveRecord::QueryCache`**
284
288
 
285
289
  * Enables the Active Record query cache.
286
290
 
287
- **`ActionDispatch::Cookies`**
291
+ **`ActionDispatch::Cookies`**
288
292
 
289
293
  * Sets cookies for the request.
290
294
 
291
- **`ActionDispatch::Session::CookieStore`**
295
+ **`ActionDispatch::Session::CookieStore`**
292
296
 
293
297
  * Responsible for storing the session in cookies.
294
298
 
295
- **`ActionDispatch::Flash`**
299
+ **`ActionDispatch::Flash`**
296
300
 
297
301
  * Sets up the flash keys. Only available if `config.action_controller.session_store` is set to a value.
298
302
 
299
- **`ActionDispatch::ParamsParser`**
303
+ **`ActionDispatch::ParamsParser`**
300
304
 
301
305
  * Parses out parameters from the request into `params`.
302
306
 
303
- **`ActionDispatch::Head`**
307
+ **`ActionDispatch::Head`**
304
308
 
305
309
  * Converts HEAD requests to `GET` requests and serves them as so.
306
310
 
307
- **`Rack::ConditionalGet`**
311
+ **`Rack::ConditionalGet`**
308
312
 
309
313
  * Adds support for "Conditional `GET`" so that server responds with nothing if page wasn't changed.
310
314
 
311
- **`Rack::ETag`**
315
+ **`Rack::ETag`**
312
316
 
313
317
  * Adds ETag header on all String bodies. ETags are used to validate cache.
314
318
 
315
319
  TIP: It's possible to use any of the above middlewares in your custom Rack stack.
316
320
 
317
- ### Using Rack Builder
318
-
319
- The following shows how to replace use `Rack::Builder` instead of the Rails supplied `MiddlewareStack`.
320
-
321
- <strong>Clear the existing Rails middleware stack</strong>
322
-
323
- ```ruby
324
- # config/application.rb
325
- config.middleware.clear
326
- ```
327
-
328
- <br />
329
- <strong>Add a `config.ru` file to `Rails.root`</strong>
330
-
331
- ```ruby
332
- # config.ru
333
- use MyOwnStackFromScratch
334
- run Rails.application
335
- ```
336
-
337
321
  Resources
338
322
  ---------
339
323
 
@@ -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. If the route above is modified to be:
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 | Used for |
93
- | --------- | ---------------- | ------- | -------------------------------------------- |
94
- | GET | /photos | index | display a list of all photos |
95
- | GET | /photos/new | new | return an HTML form for creating a new photo |
96
- | POST | /photos | create | create a new photo |
97
- | GET | /photos/:id | show | display a specific photo |
98
- | GET | /photos/:id/edit | edit | return an HTML form for editing a photo |
99
- | PATCH/PUT | /photos/:id | update | update a specific photo |
100
- | DELETE | /photos/:id | destroy | delete a specific photo |
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
 
@@ -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 | Used for |
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 | Used for |
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,15 @@ 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 | Named Helper |
227
- | --------- | --------------------- | ------- | ------------------- |
228
- | GET | /admin/posts | index | posts_path |
229
- | GET | /admin/posts/new | new | new_post_path |
230
- | POST | /admin/posts | create | posts_path |
231
- | GET | /admin/posts/:id | show | post_path(:id) |
232
- | GET | /admin/posts/:id/edit | edit | edit_post_path(:id) |
233
- | PATCH/PUT | /admin/posts/:id | update | post_path(:id) |
234
- | DELETE | /admin/posts/:id | destroy | post_path(:id) |
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) |
235
241
 
236
242
  ### Nested Resources
237
243
 
@@ -257,15 +263,15 @@ end
257
263
 
258
264
  In addition to the routes for magazines, this declaration will also route ads to an `AdsController`. The ad URLs require a magazine:
259
265
 
260
- | HTTP Verb | Path | Action | Used for |
261
- | --------- | ------------------------------------ | ------- | -------------------------------------------------------------------------- |
262
- | GET | /magazines/:magazine_id/ads | index | display a list of all ads for a specific magazine |
263
- | GET | /magazines/:magazine_id/ads/new | new | return an HTML form for creating a new ad belonging to a specific magazine |
264
- | POST | /magazines/:magazine_id/ads | create | create a new ad belonging to a specific magazine |
265
- | GET | /magazines/:magazine_id/ads/:id | show | display a specific ad belonging to a specific magazine |
266
- | GET | /magazines/:magazine_id/ads/:id/edit | edit | return an HTML form for editing an ad belonging to a specific magazine |
267
- | PATCH/PUT | /magazines/:magazine_id/ads/:id | update | update a specific ad belonging to a specific magazine |
268
- | DELETE | /magazines/:magazine_id/ads/:id | destroy | delete a specific ad belonging to a specific magazine |
266
+ | HTTP Verb | Path | Controller#Action | Used for |
267
+ | --------- | ------------------------------------ | ----------------- | -------------------------------------------------------------------------- |
268
+ | GET | /magazines/:magazine_id/ads | ads#index | display a list of all ads for a specific magazine |
269
+ | GET | /magazines/:magazine_id/ads/new | ads#new | return an HTML form for creating a new ad belonging to a specific magazine |
270
+ | POST | /magazines/:magazine_id/ads | ads#create | create a new ad belonging to a specific magazine |
271
+ | GET | /magazines/:magazine_id/ads/:id | ads#show | display a specific ad belonging to a specific magazine |
272
+ | GET | /magazines/:magazine_id/ads/:id/edit | ads#edit | return an HTML form for editing an ad belonging to a specific magazine |
273
+ | PATCH/PUT | /magazines/:magazine_id/ads/:id | ads#update | update a specific ad belonging to a specific magazine |
274
+ | DELETE | /magazines/:magazine_id/ads/:id | ads#destroy | delete a specific ad belonging to a specific magazine |
269
275
 
270
276
  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
277
 
@@ -332,7 +338,7 @@ shallow do
332
338
  end
333
339
  ```
334
340
 
335
- There exists two options for `scope` to customize shallow routes. `:shallow_path` prefixes member paths with the specified parameter:
341
+ There exist two options for `scope` to customize shallow routes. `:shallow_path` prefixes member paths with the specified parameter:
336
342
 
337
343
  ```ruby
338
344
  scope shallow_path: "sekret" do
@@ -344,15 +350,15 @@ end
344
350
 
345
351
  The comments resource here will have the following routes generated for it:
346
352
 
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 |
353
+ | HTTP Verb | Path | Controller#Action | Named Helper |
354
+ | --------- | -------------------------------------- | ----------------- | ------------------- |
355
+ | GET | /posts/:post_id/comments(.:format) | comments#index | post_comments |
356
+ | POST | /posts/:post_id/comments(.:format) | comments#create | post_comments |
357
+ | GET | /posts/:post_id/comments/new(.:format) | comments#new | new_post_comment |
358
+ | GET | /sekret/comments/:id/edit(.:format) | comments#edit | edit_comment |
359
+ | GET | /sekret/comments/:id(.:format) | comments#show | comment |
360
+ | PATCH/PUT | /sekret/comments/:id(.:format) | comments#update | comment |
361
+ | DELETE | /sekret/comments/:id(.:format) | comments#destroy | comment |
356
362
 
357
363
  The `:shallow_prefix` option adds the specified parameter to the named helpers:
358
364
 
@@ -366,19 +372,19 @@ end
366
372
 
367
373
  The comments resource here will have the following routes generated for it:
368
374
 
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 |
375
+ | HTTP Verb | Path | Controller#Action | Named Helper |
376
+ | --------- | -------------------------------------- | ----------------- | ------------------- |
377
+ | GET | /posts/:post_id/comments(.:format) | comments#index | post_comments |
378
+ | POST | /posts/:post_id/comments(.:format) | comments#create | post_comments |
379
+ | GET | /posts/:post_id/comments/new(.:format) | comments#new | new_post_comment |
380
+ | GET | /comments/:id/edit(.:format) | comments#edit | edit_sekret_comment |
381
+ | GET | /comments/:id(.:format) | comments#show | sekret_comment |
382
+ | PATCH/PUT | /comments/:id(.:format) | comments#update | sekret_comment |
383
+ | DELETE | /comments/:id(.:format) | comments#destroy | sekret_comment |
378
384
 
379
385
  ### Routing concerns
380
386
 
381
- Routing Concerns allows you to declare common routes that can be reused inside others resources and routes. To define a concern:
387
+ Routing Concerns allows you to declare common routes that can be reused inside other resources and routes. To define a concern:
382
388
 
383
389
  ```ruby
384
390
  concern :commentable do
@@ -479,7 +485,10 @@ end
479
485
 
480
486
  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
487
 
482
- Within the block of member routes, each route name specifies the HTTP verb that it will recognize. You can use `get`, `patch`, `put`, `post`, or `delete` here. If you don't have multiple `member` routes, you can also pass `:on` to a route, eliminating the block:
488
+ Within the block of member routes, each route name specifies the HTTP verb
489
+ will be recognized. You can use `get`, `patch`, `put`, `post`, or `delete` here
490
+ . If you don't have multiple `member` routes, you can also pass `:on` to a
491
+ route, eliminating the block:
483
492
 
484
493
  ```ruby
485
494
  resources :photos do
@@ -767,11 +776,11 @@ You can also reuse dynamic segments from the match in the path to redirect to:
767
776
  get '/stories/:name', to: redirect('/posts/%{name}')
768
777
  ```
769
778
 
770
- You can also provide a block to redirect, which receives the params and the request object:
779
+ You can also provide a block to redirect, which receives the symbolized path parameters and the request object:
771
780
 
772
781
  ```ruby
773
- get '/stories/:name', to: redirect {|params, req| "/posts/#{params[:name].pluralize}" }
774
- get '/stories', to: redirect {|p, req| "/posts/#{req.subdomain}" }
782
+ get '/stories/:name', to: redirect {|path_params, req| "/posts/#{path_params[:name].pluralize}" }
783
+ get '/stories', to: redirect {|path_params, req| "/posts/#{req.subdomain}" }
775
784
  ```
776
785
 
777
786
  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 +812,7 @@ You should put the `root` route at the top of the file, because it is the most p
803
812
 
804
813
  NOTE: The `root` route only routes `GET` requests to the action.
805
814
 
806
- You can also use root inside namespaces and scopes as well. For example:
815
+ You can also use root inside namespaces and scopes as well. For example:
807
816
 
808
817
  ```ruby
809
818
  namespace :admin do
@@ -836,15 +845,15 @@ resources :photos, controller: 'images'
836
845
 
837
846
  will recognize incoming paths beginning with `/photos` but route to the `Images` controller:
838
847
 
839
- | HTTP Verb | Path | Action | Named Helper |
840
- | --------- | ---------------- | ------- | -------------------- |
841
- | GET | /photos | index | photos_path |
842
- | GET | /photos/new | new | new_photo_path |
843
- | POST | /photos | create | photos_path |
844
- | GET | /photos/:id | show | photo_path(:id) |
845
- | GET | /photos/:id/edit | edit | edit_photo_path(:id) |
846
- | PATCH/PUT | /photos/:id | update | photo_path(:id) |
847
- | DELETE | /photos/:id | destroy | photo_path(:id) |
848
+ | HTTP Verb | Path | Controller#Action | Named Helper |
849
+ | --------- | ---------------- | ----------------- | -------------------- |
850
+ | GET | /photos | images#index | photos_path |
851
+ | GET | /photos/new | images#new | new_photo_path |
852
+ | POST | /photos | images#create | photos_path |
853
+ | GET | /photos/:id | images#show | photo_path(:id) |
854
+ | GET | /photos/:id/edit | images#edit | edit_photo_path(:id) |
855
+ | PATCH/PUT | /photos/:id | images#update | photo_path(:id) |
856
+ | DELETE | /photos/:id | images#destroy | photo_path(:id) |
848
857
 
849
858
  NOTE: Use `photos_path`, `new_photo_path`, etc. to generate paths for this resource.
850
859
 
@@ -857,8 +866,8 @@ resources :user_permissions, controller: 'admin/user_permissions'
857
866
  This will route to the `Admin::UserPermissions` controller.
858
867
 
859
868
  NOTE: Only the directory notation is supported. Specifying the
860
- controller with ruby constant notation (eg. `:controller =>
861
- 'Admin::UserPermissions'`) can lead to routing problems and results in
869
+ controller with Ruby constant notation (eg. `controller: 'Admin::UserPermissions'`)
870
+ can lead to routing problems and results in
862
871
  a warning.
863
872
 
864
873
  ### Specifying Constraints
@@ -894,15 +903,15 @@ resources :photos, as: 'images'
894
903
 
895
904
  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
905
 
897
- | HTTP Verb | Path | Action | Named Helper |
898
- | --------- | ---------------- | ------- | -------------------- |
899
- | GET | /photos | index | images_path |
900
- | GET | /photos/new | new | new_image_path |
901
- | POST | /photos | create | images_path |
902
- | GET | /photos/:id | show | image_path(:id) |
903
- | GET | /photos/:id/edit | edit | edit_image_path(:id) |
904
- | PATCH/PUT | /photos/:id | update | image_path(:id) |
905
- | DELETE | /photos/:id | destroy | image_path(:id) |
906
+ | HTTP Verb | Path | Controller#Action | Named Helper |
907
+ | --------- | ---------------- | ----------------- | -------------------- |
908
+ | GET | /photos | photos#index | images_path |
909
+ | GET | /photos/new | photos#new | new_image_path |
910
+ | POST | /photos | photos#create | images_path |
911
+ | GET | /photos/:id | photos#show | image_path(:id) |
912
+ | GET | /photos/:id/edit | photos#edit | edit_image_path(:id) |
913
+ | PATCH/PUT | /photos/:id | photos#update | image_path(:id) |
914
+ | DELETE | /photos/:id | photos#destroy | image_path(:id) |
906
915
 
907
916
  ### Overriding the `new` and `edit` Segments
908
917
 
@@ -999,15 +1008,15 @@ end
999
1008
 
1000
1009
  Rails now creates routes to the `CategoriesController`.
1001
1010
 
1002
- | HTTP Verb | Path | Action | Used for |
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) |
1011
+ | HTTP Verb | Path | Controller#Action | Named Helper |
1012
+ | --------- | -------------------------- | ------------------ | ----------------------- |
1013
+ | GET | /kategorien | categories#index | categories_path |
1014
+ | GET | /kategorien/neu | categories#new | new_category_path |
1015
+ | POST | /kategorien | categories#create | categories_path |
1016
+ | GET | /kategorien/:id | categories#show | category_path(:id) |
1017
+ | GET | /kategorien/:id/bearbeiten | categories#edit | edit_category_path(:id) |
1018
+ | PATCH/PUT | /kategorien/:id | categories#update | category_path(:id) |
1019
+ | DELETE | /kategorien/:id | categories#destroy | category_path(:id) |
1011
1020
 
1012
1021
  ### Overriding the Singular Form
1013
1022