aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/metal/url_for.rb13
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb4
-rw-r--r--actionpack/lib/action_dispatch/routing/url_for.rb15
-rw-r--r--actionpack/test/controller/routing_test.rb2
-rw-r--r--actionpack/test/dispatch/prefix_generation_test.rb1
5 files changed, 25 insertions, 10 deletions
diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb
index a51fc5b8e4..ca91e1f362 100644
--- a/actionpack/lib/action_controller/metal/url_for.rb
+++ b/actionpack/lib/action_controller/metal/url_for.rb
@@ -5,11 +5,20 @@ module ActionController
include ActionDispatch::Routing::UrlFor
def url_options
- super.reverse_merge(
+ options = {}
+ if respond_to?(:env) && env
+ if _routes.equal?(env["action_dispatch.routes"])
+ options[:skip_prefix] = true
+ elsif env["action_dispatch.routes"]
+ options[:script_name] = _routes.default_url_options[:script_name]
+ end
+ end
+
+ super.merge(options).reverse_merge(
:host => request.host_with_port,
:protocol => request.protocol,
:_path_segments => request.symbolized_path_parameters
- ).merge(:script_name => request.script_name)
+ ).reverse_merge(:script_name => request.script_name)
end
def _routes
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index cb0373951f..7519d74183 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -280,10 +280,10 @@ module ActionDispatch
# Yes plz - JP
included do
routes.install_helpers(self)
- singleton_class.send(:define_method, :_routes) { routes }
+ singleton_class.send(:define_method, :_routes) { @_routes || routes }
end
- define_method(:_routes) { routes }
+ define_method(:_routes) { @_routes || routes }
end
helpers
diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb
index deaf1cdf03..5da41df485 100644
--- a/actionpack/lib/action_dispatch/routing/url_for.rb
+++ b/actionpack/lib/action_dispatch/routing/url_for.rb
@@ -129,16 +129,21 @@ module ActionDispatch
options
when nil, Hash
routes = (options ? options.delete(:routes) : nil) || _routes
- if respond_to?(:env) && env
- options[:skip_prefix] = true if routes.equal?(env["action_dispatch.routes"])
- options[:script_name] = env["ORIGINAL_SCRIPT_NAME"] if routes.equal?(env["action_dispatch.parent_routes"])
- end
- routes.url_for((options || {}).reverse_merge!(url_options).symbolize_keys)
+ _with_routes(routes) do
+ routes.url_for((options || {}).reverse_merge!(url_options).symbolize_keys)
+ end
else
polymorphic_url(options)
end
end
+
+ def _with_routes(routes)
+ old_routes, @_routes = @_routes, routes
+ yield
+ ensure
+ @_routes = old_routes
+ end
end
end
end
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 1f14607c31..a8c74a6064 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -251,7 +251,7 @@ class LegacyRouteSetTests < Test::Unit::TestCase
map.pages 'pages', :controller => 'content', :action => 'show_page', :host => 'foo.com'
end
x = setup_for_named_route
- x.expects(:url_for).with(:host => 'foo.com', :only_path => false, :controller => 'content', :action => 'show_page', :use_route => :pages, :router => rs).once
+ x.expects(:url_for).with(:host => 'foo.com', :only_path => false, :controller => 'content', :action => 'show_page', :use_route => :pages).once
x.send(:pages_url)
end
diff --git a/actionpack/test/dispatch/prefix_generation_test.rb b/actionpack/test/dispatch/prefix_generation_test.rb
index efc56c067b..49c5c82ad6 100644
--- a/actionpack/test/dispatch/prefix_generation_test.rb
+++ b/actionpack/test/dispatch/prefix_generation_test.rb
@@ -114,6 +114,7 @@ module TestGenerationPrefix
test "passing :routes to url_for to change current routes" do
env = Rack::MockRequest.env_for("/pure-awesomness/blog/bare_url_for")
env["SCRIPT_NAME"] = "/something"
+ RailsApplication.routes.default_url_options = {:script_name => "/something"}
response = ActionDispatch::Response.new(*RailsApplication.call(env))
assert_equal "/something/generate", response.body
end