aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc
diff options
context:
space:
mode:
authorMike Gunderloy <MikeG1@larkfarm.com>2008-10-20 06:15:24 -0500
committerMike Gunderloy <MikeG1@larkfarm.com>2008-10-20 06:15:24 -0500
commit6937923d5a039aeaaa15f0a4ea3d688be7d92531 (patch)
tree79881d9ad092709c49a33cd715062e15150b2375 /railties/doc
parentc3ea1054f7d03a71cc41dfb5319c317587590219 (diff)
downloadrails-6937923d5a039aeaaa15f0a4ea3d688be7d92531.tar.gz
rails-6937923d5a039aeaaa15f0a4ea3d688be7d92531.tar.bz2
rails-6937923d5a039aeaaa15f0a4ea3d688be7d92531.zip
Added note on route generation from arrays.
Diffstat (limited to 'railties/doc')
-rw-r--r--railties/doc/guides/routing/routing_outside_in.txt27
1 files changed, 27 insertions, 0 deletions
diff --git a/railties/doc/guides/routing/routing_outside_in.txt b/railties/doc/guides/routing/routing_outside_in.txt
index ff41bc0257..716c362c76 100644
--- a/railties/doc/guides/routing/routing_outside_in.txt
+++ b/railties/doc/guides/routing/routing_outside_in.txt
@@ -551,6 +551,33 @@ If you like, you can combine shallow nesting with the +:has_one+ and +:has_many+
-------------------------------------------------------
map.resources :publishers, :has_many => { :magazines => :photos }, :shallow => true
-------------------------------------------------------
+
+=== Route Generation from Arrays
+
+In addition to using the generated routing helpers, Rails can also generate RESTful routes from an array of parameters. For example, suppose you have a set of routes generated with these entries in routes.rb:
+
+[source, ruby]
+-------------------------------------------------------
+map.resources :magazines do |magazine|
+ magazine.resources :ads
+end
+-------------------------------------------------------
+
+Rails will generate helpers such as magazine_ad_path that you can use in building links:
+
+[source, ruby]
+-------------------------------------------------------
+<%= link_to "Ad details", magazine_ad_path(@magazine, @ad) %>
+-------------------------------------------------------
+
+Another way to refer to the same route is with an array of objects:
+
+[source, ruby]
+-------------------------------------------------------
+<%= link_to "Ad details", [@magazine, @ad] %>
+-------------------------------------------------------
+
+This format is especially useful when you might not know until runtime which of several types of object will be used in a particular link.
=== Namespaced Resources