aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2017-07-23 01:25:26 +0200
committerDavid Rodríguez <deivid.rodriguez@riseup.net>2017-07-24 14:28:10 +0200
commit2bd60c844ce92047e03359f4dde4b19f49de92ea (patch)
tree424cf85dc71ff003c29be7d6a54776632bf8373f /actionpack/lib
parent0449d8b6bc02f4c0a416a7c40550e3b8b988d113 (diff)
downloadrails-2bd60c844ce92047e03359f4dde4b19f49de92ea.tar.gz
rails-2bd60c844ce92047e03359f4dde4b19f49de92ea.tar.bz2
rails-2bd60c844ce92047e03359f4dde4b19f49de92ea.zip
Fix regression from multiple mountpoint support
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb5
-rw-r--r--actionpack/lib/action_dispatch/routing/routes_proxy.rb23
2 files changed, 27 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index eaa0e12b67..28809d7e67 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -658,6 +658,11 @@ module ActionDispatch
script_namer = ->(options) do
prefix_options = options.slice(*_route.segment_keys)
prefix_options[:relative_url_root] = "".freeze
+
+ if options[:_recall]
+ prefix_options.reverse_merge!(options[:_recall].slice(*_route.segment_keys))
+ end
+
# We must actually delete prefix segment keys to avoid passing them to next url_for.
_route.segment_keys.each { |k| options.delete(k) }
_routes.url_helpers.send("#{name}_path", prefix_options)
diff --git a/actionpack/lib/action_dispatch/routing/routes_proxy.rb b/actionpack/lib/action_dispatch/routing/routes_proxy.rb
index 7a6c2e95d8..af0de7366b 100644
--- a/actionpack/lib/action_dispatch/routing/routes_proxy.rb
+++ b/actionpack/lib/action_dispatch/routing/routes_proxy.rb
@@ -31,7 +31,14 @@ module ActionDispatch
def #{method}(*args)
options = args.extract_options!
options = url_options.merge((options || {}).symbolize_keys)
- options.reverse_merge!(script_name: @script_namer.call(options)) if @script_namer
+
+ if @script_namer
+ options[:script_name] = merge_script_names(
+ options[:script_name],
+ @script_namer.call(options)
+ )
+ end
+
args << options
@helpers.#{method}(*args)
end
@@ -41,6 +48,20 @@ module ActionDispatch
super
end
end
+
+ # Keeps the part of the script name provided by the global
+ # context via ENV["SCRIPT_NAME"], which `mount` doesn't know
+ # about since it depends on the specific request, but use our
+ # script name resolver for the mount point dependent part.
+ def merge_script_names(previous_script_name, new_script_name)
+ return new_script_name unless previous_script_name
+
+ resolved_parts = new_script_name.count("/")
+ previous_parts = previous_script_name.count("/")
+ context_parts = previous_parts - resolved_parts + 1
+
+ (previous_script_name.split("/").slice(0, context_parts).join("/")) + new_script_name
+ end
end
end
end