mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Routing guide: move scope documentation down to where it is referenced more plainly
This commit is contained in:
@@ -200,16 +200,6 @@ or, for a single case
|
||||
resources :posts, :path => "/admin/posts"
|
||||
</ruby>
|
||||
|
||||
You can even set named parameters for the paths:
|
||||
|
||||
<ruby>
|
||||
scope ":username" do
|
||||
resources :posts
|
||||
end
|
||||
</ruby>
|
||||
|
||||
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
|
||||
</ruby>
|
||||
|
||||
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:
|
||||
|
||||
<ruby>
|
||||
scope ":username" do
|
||||
resources :posts
|
||||
end
|
||||
</ruby>
|
||||
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user