diff options
Diffstat (limited to 'actionpack')
4 files changed, 26 insertions, 14 deletions
diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb index 6748cb7bd4..8a06f34d23 100644 --- a/actionpack/lib/action_controller/metal/url_for.rb +++ b/actionpack/lib/action_controller/metal/url_for.rb @@ -5,7 +5,7 @@ module ActionController include ActionDispatch::Routing::UrlFor include ActionController::RackDelegation - def merge_options(options) + def url_options super.reverse_merge( :host => request.host_with_port, :protocol => request.protocol, diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 0fa2a8b90c..64d9bdab2a 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -336,7 +336,7 @@ module ActionController private def build_request_uri(action, parameters) unless @request.env['REQUEST_URI'] - options = @controller.__send__(:merge_options, parameters) + options = @controller.__send__(:url_options).merge(parameters) options.update(:only_path => true, :action => action) url = ActionController::UrlRewriter.new(@request, parameters) diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index 7004c1aab3..d467929561 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -95,22 +95,26 @@ module ActionDispatch self.default_url_options = {} end - def default_url_options(options = nil) - self.class.default_url_options - end + # def default_url_options(options = nil) + # self.class.default_url_options + # end def url_options - self.class.default_url_options.merge + self.class.default_url_options.merge(@url_options || {}) end - def merge_options(options) #:nodoc: - if respond_to?(:default_url_options) && (defaults = default_url_options(options)) - defaults.merge(options) - else - options - end + def url_options=(options) + @url_options = options end + # def merge_options(options) #:nodoc: + # if respond_to?(:default_url_options) && (defaults = default_url_options(options)) + # defaults.merge(options) + # else + # options + # end + # end + # Generate a url based on the options provided, default_url_options and the # routes defined in routes.rb. The following options are supported: # @@ -140,7 +144,15 @@ module ActionDispatch when String options when Hash - ActionController::UrlRewriter.rewrite(_router, merge_options(options)) + # Handle the deprecated instance level default_url_options + if respond_to?(:default_url_options, true) + ActiveSupport::Deprecation.warn "Overwriting #default_url_options is deprecated. Please set url options with self.url_options = { ... }" + if defaults = default_url_options(options) + options = defaults.merge(options) + end + end + + ActionController::UrlRewriter.rewrite(_router, url_options.merge(options)) else polymorphic_url(options) end diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index fb067601c8..0bad9c37d6 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -357,7 +357,7 @@ module ActionDispatch extend ActiveSupport::Concern include ActionDispatch::Routing::UrlFor - def merge_options(options) + def url_options opts = super.reverse_merge( :host => host, :protocol => https? ? "https" : "http" |