This generates helpers such as account_projects_path, just like
resources does. The difference here being that the routes
generated are like /:account_id/projects, rather than
/accounts/:account_id/projects.
Options
Takes same options as Base#match and Resources#resources.
# route /posts (without the prefix /admin) to <tt>Admin::PostsController</tt>scopemodule:"admin"doresources:postsend# prefix the posts resource's requests with '/admin'scopepath:"/admin"doresources:postsend# prefix the routing helper name: +sekret_posts_path+ instead of +posts_path+scopeas:"sekret"doresources:postsend
# File actionpack/lib/action_dispatch/routing/mapper.rb, line 841
def scope(*args)
options = args.extract_options!.dup
scope = {}
options[:path] = args.flatten.join("/") if args.any?
options[:constraints] ||= {}
unless nested_scope?
options[:shallow_path] ||= options[:path] if options.key?(:path)
options[:shallow_prefix] ||= options[:as] if options.key?(:as)
end
if options[:constraints].is_a?(Hash)
defaults = options[:constraints].select do |k, v|
URL_OPTIONS.include?(k) && (v.is_a?(String) || v.is_a?(Integer))
end
options[:defaults] = defaults.merge(options[:defaults] || {})
else
block, options[:constraints] = options[:constraints], {}
end
if options.key?(:only) || options.key?(:except)
scope[:action_options] = { only: options.delete(:only),
except: options.delete(:except) }
end
if options.key? :anchor
raise ArgumentError, "anchor is ignored unless passed to `match`"
end
@scope.options.each do |option|
if option == :blocks
value = block
elsif option == :options
value = options
else
value = options.delete(option) { POISON }
end
unless POISON == value
scope[option] = send("merge_#{option}_scope", @scope[option], value)
end
end
@scope = @scope.new scope
yield
self
ensure
@scope = @scope.parent
end