From 6c14252d2cc28b97ba708971a3ad235537bcdf02 Mon Sep 17 00:00:00 2001 From: Yasyf Mohamedali Date: Tue, 24 Feb 2015 16:04:27 -0500 Subject: Fallback to RAILS_RELATIVE_URL_ROOT in `url_for`. Fixed an issue where the `RAILS_RELATIVE_URL_ROOT` environment variable is not prepended to the path when `url_for` is called. If `SCRIPT_NAME` (used by Rack) is set, it takes precedence. --- actionpack/lib/action_dispatch/railtie.rb | 2 ++ actionpack/lib/action_dispatch/routing/route_set.rb | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb index ddeea24bb3..8cde5eb6f7 100644 --- a/actionpack/lib/action_dispatch/railtie.rb +++ b/actionpack/lib/action_dispatch/railtie.rb @@ -40,6 +40,8 @@ module ActionDispatch ActionDispatch::Cookies::CookieJar.always_write_cookie = config.action_dispatch.always_write_cookie ActionDispatch.test_app = app + + ActionDispatch::Routing::RouteSet.relative_url_root = app.config.relative_url_root end end end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index ce04f0b08a..da6a00304c 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -20,6 +20,8 @@ module ActionDispatch # alias inspect to to_s. alias inspect to_s + mattr_accessor :relative_url_root + class Dispatcher < Routing::Endpoint def initialize(defaults) @defaults = defaults @@ -693,7 +695,7 @@ module ActionDispatch end def find_script_name(options) - options.delete(:script_name) || '' + options.delete(:script_name) || relative_url_root || '' end def path_for(options, route_name = nil) -- cgit v1.2.3