diff options
author | Ryan Bigg <radarlistener@gmail.com> | 2008-10-09 00:35:03 +1030 |
---|---|---|
committer | Ryan Bigg <radarlistener@gmail.com> | 2008-10-09 00:35:03 +1030 |
commit | 3979d267522f9aaef92b5f21a65abab5046cefaa (patch) | |
tree | ed383b7f9211b66a976bd57583757cfc54ce1753 /railties/doc/guides/routing | |
parent | 224060aa8287fcdd8aa5ea11320fc5f373f01459 (diff) | |
parent | b4da5f67708b2699a21f8bb39f4d10865c1814d4 (diff) | |
download | rails-3979d267522f9aaef92b5f21a65abab5046cefaa.tar.gz rails-3979d267522f9aaef92b5f21a65abab5046cefaa.tar.bz2 rails-3979d267522f9aaef92b5f21a65abab5046cefaa.zip |
Merge branch 'master' of git@github.com:lifo/docrails
Diffstat (limited to 'railties/doc/guides/routing')
-rw-r--r-- | railties/doc/guides/routing/routing_outside_in.txt | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/railties/doc/guides/routing/routing_outside_in.txt b/railties/doc/guides/routing/routing_outside_in.txt index f35ac0cebd..c3dc60c8bf 100644 --- a/railties/doc/guides/routing/routing_outside_in.txt +++ b/railties/doc/guides/routing/routing_outside_in.txt @@ -267,10 +267,28 @@ Rails allows you to group your controllers into namespaces by saving them in fol map.resources :adminphotos, :controller => "admin/photos" ------------------------------------------------------- -If you use controller namespaces, you need to be aware of a subtlety in the Rails routing code: it always tries to preserve as much of the namespace from the previous request as possible. For example, if you are on a view generated from the +adminphoto_path+ helper, and you follow a link generated with +<%= link_to "show", adminphoto(1) %> you will end up on the view generated by +admin/photos/show+ but you will also end up in the same place if you have +<%= link_to "show", {:controller => "photos", :action => "show"} %>+ because Rails will generate the show URL relative to the current URL. +If you use controller namespaces, you need to be aware of a subtlety in the Rails routing code: it always tries to preserve as much of the namespace from the previous request as possible. For example, if you are on a view generated from the +adminphoto_path+ helper, and you follow a link generated with +<%= link_to "show", adminphoto(1) %>+ you will end up on the view generated by +admin/photos/show+ but you will also end up in the same place if you have +<%= link_to "show", {:controller => "photos", :action => "show"} %>+ because Rails will generate the show URL relative to the current URL. TIP: If you want to guarantee that a link goes to a top-level controller, use a preceding slash to anchor the controller name: +<%= link_to "show", {:controller => "/photos", :action => "show"} %>+ +You can also specify a controller namespace with the +:namespace+ option instead of a path: + +[source, ruby] +------------------------------------------------------- +map.resources :adminphotos, :namespace => "admin", :controller => "photos" +------------------------------------------------------- + +This can be especially useful when combined with +with_options+ to map multiple namespaced routes together: + +[source, ruby] +------------------------------------------------------- +map.with_options(:namespace => "admin") do |admin| + admin.resources :photos, :videos +end +------------------------------------------------------- + +That would give you routing for +admin/photos+ and +admin/videos+ controllers. + ==== Using :singular If for some reason Rails isn't doing what you want in converting the plural resource name to a singular name in member routes, you can override its judgment with the +:singular+ option: |