scope
- 1.0.0
- 1.1.0
- 1.1.1
- 1.1.6
- 1.2.0
- 1.2.6
- 2.0.0
- 2.0.1
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.2
- 2.3.8
- 3.0.0 (0)
- 3.0.5 (38)
- 3.0.7 (0)
- 3.0.9 (-2)
- 3.1.0 (-17)
- 3.2.1 (0)
- 3.2.3 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- What's this?
scope(*args)
public
Used to scope a set of routes to particular constraints.
Take the following route definition as an example:
scope :path => ":account_id", :as => "account" do resources :projects end
This generates helpers such as account_projects_path, just like resources does. The difference here being that the routes generated are like /rails/projects/2, rather than /accounts/rails/projects/2.
Supported options
- :module
- If you want to route /posts (without the prefix /admin) to
Admin::PostsController, you could use
scope :module => "admin" do resources :posts end
- :path
- If you want to prefix the route, you could use
scope :path => "/admin" do resources :posts end
This will prefix all of the posts resource’s requests with ’/admin’
- :as
- Prefixes the routing helpers in this scope with
the specified label.
scope :as => "sekret" do resources :posts end
Helpers such as posts_path will now be sekret_posts_path
[:shallow_path]
Prefixes nested shallow routes with the specified path. scope :shallow_path => "sekret" do resources :posts do resources :comments, :shallow => true end The +comments+ resource here will have the following routes generated for it: post_comments GET /sekret/posts/:post_id/comments(.:format) post_comments POST /sekret/posts/:post_id/comments(.:format) new_post_comment GET /sekret/posts/:post_id/comments/new(.:format) edit_comment GET /sekret/comments/:id/edit(.:format) comment GET /sekret/comments/:id(.:format) comment PUT /sekret/comments/:id(.:format) comment DELETE /sekret/comments/:id(.:format)


