diff options
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index da0970d110..a0d12144c4 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -70,7 +70,7 @@ module ActionDispatch options.delete :shallow_prefix options.delete :shallow - defaults = (scope[:defaults] || {}).merge options.delete(:defaults) || {} + defaults = (scope[:defaults] || {}).dup new scope, set, path, defaults, as, options end @@ -684,7 +684,11 @@ module ActionDispatch def map_method(method, args, &block) options = args.extract_options! options[:via] = method - match(*args, options, &block) + if options.key?(:defaults) + defaults(options.delete(:defaults)) { match(*args, options, &block) } + else + match(*args, options, &block) + end self end end @@ -787,8 +791,8 @@ module ActionDispatch 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?(Fixnum)) + defaults = options[:constraints].select do |k, v| + URL_OPTIONS.include?(k) && (v.is_a?(String) || v.is_a?(Fixnum)) end (options[:defaults] ||= {}).reverse_merge!(defaults) @@ -822,9 +826,11 @@ module ActionDispatch # controller "food" do # match "bacon", action: :bacon, via: :get # end - def controller(controller, options={}) - options[:controller] = controller - scope(options) { yield } + def controller(controller) + @scope = @scope.new(controller: controller) + yield + ensure + @scope = @scope.parent end # Scopes routes to a specific namespace. For example: @@ -944,7 +950,10 @@ module ActionDispatch # end # Using this, the +:id+ parameter here will default to 'home'. def defaults(defaults = {}) - scope(:defaults => defaults) { yield } + @scope = @scope.new(defaults: merge_defaults_scope(@scope[:defaults], defaults)) + yield + ensure + @scope = @scope.parent end private @@ -1681,7 +1690,7 @@ module ActionDispatch def resource_scope(resource) #:nodoc: @scope = @scope.new(:scope_level_resource => resource) - controller_scope(resource.resource_scope) { yield } + controller(resource.resource_scope) { yield } ensure @scope = @scope.parent end @@ -1791,13 +1800,6 @@ module ActionDispatch end private - def controller_scope(controller) - @scope = @scope.new(controller: controller) - yield - ensure - @scope = @scope.parent - end - def path_scope(path) @scope = @scope.new(path: merge_path_scope(@scope[:path], path)) yield |