diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-03-05 13:11:53 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-03-05 13:12:06 -0800 |
commit | 798a14a6388ac525109e550d72bba0b1118e5e2e (patch) | |
tree | cad588c08fd1a4aa2e7a67c3899d131146f14e05 /actionpack/lib/action_dispatch | |
parent | ad23aab7b30612d77bf746e6c0ae7a7140de0144 (diff) | |
download | rails-798a14a6388ac525109e550d72bba0b1118e5e2e.tar.gz rails-798a14a6388ac525109e550d72bba0b1118e5e2e.tar.bz2 rails-798a14a6388ac525109e550d72bba0b1118e5e2e.zip |
pass a config to the route set
This way we can get the relative_url_root from the application without
setting another global value
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/railtie.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 22 |
2 files changed, 19 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb index 8cde5eb6f7..ddeea24bb3 100644 --- a/actionpack/lib/action_dispatch/railtie.rb +++ b/actionpack/lib/action_dispatch/railtie.rb @@ -40,8 +40,6 @@ 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 6d964c2cbf..0f3734dd74 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -20,8 +20,6 @@ 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 @@ -320,11 +318,25 @@ module ActionDispatch { :new => 'new', :edit => 'edit' } end - def initialize + def self.new_with_config(config) + if config.respond_to? :relative_url_root + new Config.new config.relative_url_root + else + # engines apparently don't have this set + new + end + end + + Config = Struct.new :relative_url_root + + DEFAULT_CONFIG = Config.new(nil) + + def initialize(config = DEFAULT_CONFIG) self.named_routes = NamedRouteCollection.new self.resources_path_names = self.class.default_resources_path_names self.default_url_options = {} + @config = config @append = [] @prepend = [] @disable_clear_and_finalize = false @@ -336,6 +348,10 @@ module ActionDispatch @formatter = Journey::Formatter.new @set end + def relative_url_root + @config.relative_url_root + end + def request_class ActionDispatch::Request end |