aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-02-26 15:20:41 -0800
committerCarlhuda <carlhuda@engineyard.com>2010-02-26 15:20:41 -0800
commitbae691f61ab8cf4a59adaee6406855e11d009c74 (patch)
tree30dbf62a2f8cce56498fc8d92b35a2d5ff0a66a8
parent224c0318bdbaea354bc5ab5c70b267b2a9c3d1c9 (diff)
downloadrails-bae691f61ab8cf4a59adaee6406855e11d009c74.tar.gz
rails-bae691f61ab8cf4a59adaee6406855e11d009c74.tar.bz2
rails-bae691f61ab8cf4a59adaee6406855e11d009c74.zip
Change the API for setting global options for #url_for to self.url_options = { ... }
This attr_accessor can be set in a before filter or in the action itself. Overwriting default_url_options still works but will output a deprecation notice.
-rw-r--r--actionpack/lib/action_controller/metal/url_for.rb2
-rw-r--r--actionpack/lib/action_controller/test_case.rb2
-rw-r--r--actionpack/lib/action_dispatch/routing/url_for.rb34
-rw-r--r--actionpack/lib/action_dispatch/testing/integration.rb2
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"