aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing
diff options
context:
space:
mode:
authorAlberto Almagro <albertoalmagro@gmail.com>2018-12-08 22:42:40 +0100
committerAlberto Almagro <albertoalmagro@gmail.com>2019-05-22 23:03:54 +0200
commitfb9117e190e39872fff7ae5d6b96bfb26ef8b32c (patch)
tree6269b64939b1a15b672c1deb4b871b3b3e9256fb /actionpack/lib/action_dispatch/routing
parentd5a2f7ec148726d7547e367d7a968e3b4be9b509 (diff)
downloadrails-fb9117e190e39872fff7ae5d6b96bfb26ef8b32c.tar.gz
rails-fb9117e190e39872fff7ae5d6b96bfb26ef8b32c.tar.bz2
rails-fb9117e190e39872fff7ae5d6b96bfb26ef8b32c.zip
Keep part when scope option has value
When a route was defined within an optional scope, if that route didn't take parameters the scope was lost when using path helpers. This patch ensures scope is kept both when the route takes parameters or when it doesn't. Fixes #33219
Diffstat (limited to 'actionpack/lib/action_dispatch/routing')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb13
1 files changed, 7 insertions, 6 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index f29f66990d..695eed3adc 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -70,17 +70,17 @@ module ActionDispatch
ANCHOR_CHARACTERS_REGEX = %r{\A(\\A|\^)|(\\Z|\\z|\$)\Z}
OPTIONAL_FORMAT_REGEX = %r{(?:\(\.:format\)+|\.:format|/)\Z}
- attr_reader :requirements, :defaults
- attr_reader :to, :default_controller, :default_action
- attr_reader :required_defaults, :ast
+ attr_reader :requirements, :defaults, :to, :default_controller,
+ :default_action, :required_defaults, :ast, :scope_options
def self.build(scope, set, ast, controller, default_action, to, via, formatted, options_constraints, anchor, options)
options = scope[:options].merge(options) if scope[:options]
defaults = (scope[:defaults] || {}).dup
scope_constraints = scope[:constraints] || {}
+ scope_options = scope[:options] || {}
- new set, ast, defaults, controller, default_action, scope[:module], to, formatted, scope_constraints, scope[:blocks] || [], via, options_constraints, anchor, options
+ new set, ast, defaults, controller, default_action, scope[:module], to, formatted, scope_constraints, scope_options, scope[:blocks] || [], via, options_constraints, anchor, options
end
def self.check_via(via)
@@ -111,7 +111,7 @@ module ActionDispatch
format != false && path !~ OPTIONAL_FORMAT_REGEX
end
- def initialize(set, ast, defaults, controller, default_action, modyoule, to, formatted, scope_constraints, blocks, via, options_constraints, anchor, options)
+ def initialize(set, ast, defaults, controller, default_action, modyoule, to, formatted, scope_constraints, scope_options, blocks, via, options_constraints, anchor, options)
@defaults = defaults
@set = set
@@ -122,6 +122,7 @@ module ActionDispatch
@anchor = anchor
@via = via
@internal = options.delete(:internal)
+ @scope_options = scope_options
path_params = ast.find_all(&:symbol?).map(&:to_sym)
@@ -161,7 +162,7 @@ module ActionDispatch
def make_route(name, precedence)
Journey::Route.new(name, application, path, conditions, required_defaults,
- defaults, request_method, precedence, @internal)
+ defaults, request_method, precedence, scope_options, @internal)
end
def application