public
Description: Repository for improving Rails documentation
Homepage: http://www.rubyonrails.org
Clone URL: git://github.com/lifo/doc-rails.git
Search Repo:
mostly markup revision of resources path generator docs
Xavier Noria (author)
Tue Apr 22 03:11:05 -0700 2008
commit  e4d2621f409d2477a3b3684a8a35a0d2c503b38b
tree    56be5e7b3beb9b77335216e02c411456fdcc8a0e
parent  30882b0abf7441e3ca9c35c7ec0218f2ac61a5f9
...
189
190
191
192
 
193
194
195
196
197
198
...
206
207
208
209
 
210
211
212
213
214
215
 
216
217
218
219
 
220
221
222
223
224
225
226
...
227
228
229
230
 
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
 
 
 
 
 
 
 
 
 
 
 
248
249
250
251
252
 
 
 
253
254
255
 
256
257
258
259
260
261
...
266
267
268
269
 
270
271
272
273
274
...
287
288
289
290
 
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
 
 
 
 
 
 
 
 
 
 
 
 
306
307
308
309
310
311
...
334
335
336
337
 
338
339
340
...
189
190
191
 
192
193
194
195
196
197
198
...
206
207
208
 
209
210
211
 
212
213
 
214
215
216
 
 
217
218
219
220
221
222
223
224
...
225
226
227
 
228
229
230
231
232
233
234
 
 
 
 
 
 
 
 
 
 
 
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
 
 
255
256
 
 
257
258
259
...
264
265
266
 
267
268
269
270
271
272
...
285
286
287
 
288
289
290
291
292
293
 
 
 
 
 
 
 
 
 
 
294
295
296
297
298
299
300
301
302
303
304
305
306
 
 
307
308
309
...
332
333
334
 
335
336
337
338
0
@@ -189,7 +189,7 @@
0
     # end
0
     # end
0
     #
0
- # Along with the routes themselves, #resources generates named routes for use in
0
+ # Along with the routes themselves, +resources+ generates named routes for use in
0
     # controllers and views. <tt>map.resources :messages</tt> produces the following named routes and helpers:
0
     #
0
     # Named Route Helpers
0
0
0
0
@@ -206,17 +206,15 @@
0
     # edit_message edit_message_url(id), hash_for_edit_message_url(id),
0
     # edit_message_path(id), hash_for_edit_message_path(id)
0
     #
0
- # You can use these helpers instead of #url_for or methods that take #url_for parameters. For example:
0
+ # You can use these helpers instead of +url_for+ or methods that take +url_for+ parameters. For example:
0
     #
0
     # redirect_to :controller => 'messages', :action => 'index'
0
- # # and
0
     # <%= link_to "edit this message", :controller => 'messages', :action => 'edit', :id => @message.id %>
0
     #
0
- # now become:
0
+ # now respectively become:
0
     #
0
     # redirect_to messages_url
0
- # # and
0
- # <%= link_to "edit this message", edit_message_url(@message) # calls @message.id automatically
0
+ # <%= link_to "edit this message", edit_message_url(@message) %> <%# calls @message.id automatically %>
0
     #
0
     # Since web browsers don't support the PUT and DELETE verbs, you will need to add a parameter '_method' to your
0
     # form tags. The form helpers make this a little easier. For an update form with a <tt>@message</tt> object:
0
0
0
0
0
@@ -227,35 +225,35 @@
0
     #
0
     # <% form_for :message, @message, :url => message_path(@message), :html => {:method => :put} do |f| %>
0
     #
0
- # or
0
+ # or just
0
     #
0
     # <% form_for @message do |f| %>
0
     #
0
     # which takes into account whether <tt>@message</tt> is a new record or not and generates the
0
     # path and method accordingly.
0
     #
0
- # The #resources method accepts the following options to customize the resulting routes:
0
- # * <tt>:collection</tt> - add named routes for other actions that operate on the collection.
0
- # Takes a hash of <tt>#{action} => #{method}</tt>, where method is <tt>:get</tt>/<tt>:post</tt>/<tt>:put</tt>/<tt>:delete</tt>
0
- # or <tt>:any</tt> if the method does not matter. These routes map to a URL like /messages/rss, with a route of rss_messages_url.
0
- # * <tt>:member</tt> - same as <tt>:collection</tt>, but for actions that operate on a specific member.
0
- # * <tt>:new</tt> - same as <tt>:collection</tt>, but for actions that operate on the new resource action.
0
- # * <tt>:controller</tt> - specify the controller name for the routes.
0
- # * <tt>:singular</tt> - specify the singular name used in the member routes.
0
- # * <tt>:requirements</tt> - set custom routing parameter requirements.
0
- # * <tt>:conditions</tt> - specify custom routing recognition conditions. Resources sets the <tt>:method</tt> value for the method-specific routes.
0
- # * <tt>:as</tt> - specify a different resource name to use in the URL path. For example:
0
+ # The +resources+ method accepts the following options to customize the resulting routes:
0
+ # * <tt>:collection</tt> - Add named routes for other actions that operate on the collection.
0
+ # Takes a hash of <tt>action => method</tt>, where method is <tt>:get</tt>/<tt>:post</tt>/<tt>:put</tt>/<tt>:delete</tt>
0
+ # or <tt>:any</tt> if the method does not matter. These routes map to a URL like /messages/rss, with a route of +rss_messages_url+.
0
+ # * <tt>:member</tt> - Same as <tt>:collection</tt>, but for actions that operate on a specific member.
0
+ # * <tt>:new</tt> - Same as <tt>:collection</tt>, but for actions that operate on the new resource action.
0
+ # * <tt>:controller</tt> - Specify the controller name for the routes.
0
+ # * <tt>:singular</tt> - Specify the singular name used in the member routes.
0
+ # * <tt>:requirements</tt> - Set custom routing parameter requirements.
0
+ # * <tt>:conditions</tt> - Specify custom routing recognition conditions. Resources sets the <tt>:method</tt> value for the method-specific routes.
0
+ # * <tt>:as</tt> - Specify a different resource name to use in the URL path. For example:
0
     # # products_path == '/productos'
0
     # map.resources :products, :as => 'productos' do |product|
0
     # # product_reviews_path(product) == '/productos/1234/comentarios'
0
     # product.resources :product_reviews, :as => 'comentarios'
0
     # end
0
+ # Note that the name of the path generator method is still based on the original resource name.
0
+ # * <tt>:has_one</tt> - Specify nested resources, this is a shorthand for mapping singleton resources beneath the current.
0
+ # * <tt>:has_many</tt> - Same has <tt>:has_one</tt>, but for plural resources.
0
     #
0
- # * <tt>:has_one</tt> - specify nested resources, this is a shorthand for mapping singleton resources beneath the current.
0
- # * <tt>:has_many</tt> - same has <tt>:has_one</tt>, but for plural resources.
0
+ # You may directly specify the routing association with +has_one+ and +has_many+ like:
0
     #
0
- # You may directly specify the routing association with has_one and has_many like:
0
- #
0
     # map.resources :notes, :has_one => :author, :has_many => [:comments, :attachments]
0
     #
0
     # This is the same as:
0
@@ -266,7 +264,7 @@
0
     # notes.resources :attachments
0
     # end
0
     #
0
- # * <tt>:path_prefix</tt> - set a prefix to the routes with required route variables.
0
+ # * <tt>:path_prefix</tt> - Set a prefix to the routes with required route variables.
0
     #
0
     # Weblog comments usually belong to a post, so you might use resources like:
0
     #
0
0
0
@@ -287,25 +285,25 @@
0
     # article_comments_url(:article_id => @article)
0
     # article_comment_url(:article_id => @article, :id => @comment)
0
     #
0
- # * <tt>:name_prefix</tt> - define a prefix for all generated routes, usually ending in an underscore.
0
+ # * <tt>:name_prefix</tt> - Define a prefix for all generated routes, usually ending in an underscore.
0
     # Use this if you have named routes that may clash.
0
     #
0
     # map.resources :tags, :path_prefix => '/books/:book_id', :name_prefix => 'book_'
0
     # map.resources :tags, :path_prefix => '/toys/:toy_id', :name_prefix => 'toy_'
0
     #
0
- # You may also use <tt>:name_prefix</tt> to override the generic named routes in a nested resource:
0
- #
0
- # map.resources :articles do |article|
0
- # article.resources :comments, :name_prefix => nil
0
- # end
0
- #
0
- # This will yield named resources like so:
0
- #
0
- # comments_url(@article)
0
- # comment_url(@article, @comment)
0
+ # You may also use <tt>:name_prefix</tt> to override the generic named routes in a nested resource:
0
+ #
0
+ # map.resources :articles do |article|
0
+ # article.resources :comments, :name_prefix => nil
0
+ # end
0
+ #
0
+ # This will yield named resources like so:
0
+ #
0
+ # comments_url(@article)
0
+ # comment_url(@article, @comment)
0
+ #
0
+ # If <tt>map.resources</tt> is called with multiple resources, they all get the same options applied.
0
     #
0
- # If <tt>map.resources</tt> is called with multiple resources, they all get the same options applied.
0
- #
0
     # Examples:
0
     #
0
     # map.resources :messages, :path_prefix => "/thread/:thread_id"
0
@@ -334,7 +332,7 @@
0
     # # --> GET /categories/7/messages/1
0
     # # has named route "category_message"
0
     #
0
- # The #resources method sets HTTP method restrictions on the routes it generates. For example, making an
0
+ # The +resources+ method sets HTTP method restrictions on the routes it generates. For example, making an
0
     # HTTP POST on <tt>new_message_url</tt> will raise a RoutingError exception. The default route in
0
     # <tt>config/routes.rb</tt> overrides this and allows invalid HTTP methods for resource routes.
0
     def resources(*entities, &block)

Comments

    No one has commented yet.