From eaf67ca9c3fbe3e45c8096ea7ffbde562ebfb76d Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Fri, 31 Dec 2010 17:38:04 +1000 Subject: Routing guide: improve documentation for the scope method, demonstrating use of named parameters --- railties/guides/source/routing.textile | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 15b26d8f9e..fda5c6c668 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -200,6 +200,16 @@ or, for a single case resources :posts, :path => "/admin/posts" +You can even set named parameters for the paths: + + +scope ":username" do + resources :posts +end + + +This will provide you with URLs such as +/bob/posts/1+ and will allow you to reference the +username+ part of the path as +params[:username]+ in controllers, helpers and views. + 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+: |_.HTTP Verb |_.Path |_.action |_.named helper | -- cgit v1.2.3 From 9aef64f7a347cdc1eab70b44f55a050e28af5074 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Fri, 31 Dec 2010 17:45:03 +1000 Subject: Routing guide: move scope documentation down to where it is referenced more plainly --- railties/guides/source/routing.textile | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index fda5c6c668..b1cef26932 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -200,16 +200,6 @@ or, for a single case resources :posts, :path => "/admin/posts" -You can even set named parameters for the paths: - - -scope ":username" do - resources :posts -end - - -This will provide you with URLs such as +/bob/posts/1+ and will allow you to reference the +username+ part of the path as +params[:username]+ in controllers, helpers and views. - 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+: |_.HTTP Verb |_.Path |_.action |_.named helper | @@ -724,8 +714,20 @@ end resources :photos, :accounts +This will generate routes such as +admin_photos_path+ and +admin_accounts_path+. + NOTE: The +namespace+ scope will automatically add +:as+ as well as +:module+ and +:path+ prefixes. +You can prefix routes with a named parameter also: + + +scope ":username" do + resources :posts +end + + +This will provide you with URLs such as +/bob/posts/1+ and will allow you to reference the +username+ part of the path as +params[:username]+ in controllers, helpers and views. + h4. Restricting the Routes Created By default, Rails creates routes for the seven default actions (index, show, new, create, edit, update, and destroy) for every RESTful route in your application. You can use the +:only+ and +:except+ options to fine-tune this behavior. The +:only+ option tells Rails to create only the specified routes: -- cgit v1.2.3 From 224e2d478a825c312128a1b3c2797d0a95fd7109 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Fri, 31 Dec 2010 17:50:37 +1000 Subject: Routing guide: clarify what the :as option does for scopes --- railties/guides/source/routing.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index b1cef26932..f60d72352d 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -704,7 +704,7 @@ resources :photos This will provide route helpers such as +admin_photos_path+, +new_admin_photo_path+ etc. -To prefix a group of routes, use +:as+ with +scope+: +To prefix a group of route helpers, use +:as+ with +scope+: scope "admin", :as => "admin" do @@ -714,7 +714,7 @@ end resources :photos, :accounts -This will generate routes such as +admin_photos_path+ and +admin_accounts_path+. +This will generate routes such as +admin_photos_path+ and +admin_accounts_path+ which map to +/admin/photos+ and +/admin/accounts+ respectively. NOTE: The +namespace+ scope will automatically add +:as+ as well as +:module+ and +:path+ prefixes. -- cgit v1.2.3