diff options
author | Mike Gunderloy <MikeG1@larkfarm.com> | 2008-10-07 06:03:53 -0500 |
---|---|---|
committer | Mike Gunderloy <MikeG1@larkfarm.com> | 2008-10-07 06:03:53 -0500 |
commit | 3da0c0a8424ce018fa756e906e824698dfdcb65e (patch) | |
tree | de06670ab87656193664d3bd3e3459bae388fa64 /railties/doc/guides/routing | |
parent | 973bd54d83f38747015e3d85d7f9fa1ee86b6270 (diff) | |
download | rails-3da0c0a8424ce018fa756e906e824698dfdcb65e.tar.gz rails-3da0c0a8424ce018fa756e906e824698dfdcb65e.tar.bz2 rails-3da0c0a8424ce018fa756e906e824698dfdcb65e.zip |
Additional detail on routes for namespaced controllers.
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: |