module ActionDispatch::Routing::Mapper::Scoping
def scope(*args)
comment PUT /sekret/comments/:id(.:format)
comment GET /sekret/comments/:id(.:format)
edit_comment GET /sekret/comments/:id/edit(.:format)
new_post_comment GET /sekret/posts/:post_id/comments/new(.:format)
post_comments POST /sekret/posts/:post_id/comments(.:format)
post_comments GET /sekret/posts/:post_id/comments(.:format)
The +comments+ resource here will have the following routes generated for it:
end
resources :comments, :shallow => true
resources :posts do
scope :shallow_path => "sekret" do
Prefixes nested shallow routes with the specified path.
[:shallow_path]
Helpers such as +posts_path+ will now be +sekret_posts_path+
end
resources :posts
scope :as => "sekret" do
Prefixes the routing helpers in this scope with the specified label.
[:as]
This will prefix all of the +posts+ resource's requests with '/admin'
end
resources :posts
scope :path => "/admin" do
If you want to prefix the route, you could use
[:path]
end
resources :posts
scope :module => "admin" do
Admin::PostsController, you could use
If you want to route /posts (without the prefix /admin) to
[:module]
=== Supported options
rather than /accounts/rails/projects/2.
The difference here being that the routes generated are like /rails/projects/2,
This generates helpers such as +account_projects_path+, just like +resources+ does.
end
resources :projects
scope :path => ":account_id", :as => "account" do
Take the following route definition as an example:
Used to scope a set of routes to particular constraints.
def scope(*args) options = args.extract_options! options = options.dup if name_prefix = options.delete(:name_prefix) options[:as] ||= name_prefix ActiveSupport::Deprecation.warn ":name_prefix was deprecated in the new router syntax. Use :as instead.", caller end options[:path] = args.first if args.first.is_a?(String) recover = {} options[:constraints] ||= {} unless options[:constraints].is_a?(Hash) block, options[:constraints] = options[:constraints], {} end scope_options.each do |option| if value = options.delete(option) recover[option] = @scope[option] @scope[option] = send("merge_#{option}_scope", @scope[option], value) end end recover[:block] = @scope[:blocks] @scope[:blocks] = merge_blocks_scope(@scope[:blocks], block) recover[:options] = @scope[:options] @scope[:options] = merge_options_scope(@scope[:options], options) yield self ensure scope_options.each do |option| @scope[option] = recover[option] if recover.has_key?(option) end @scope[:options] = recover[:options] @scope[:blocks] = recover[:block] end