diff options
author | Carlhuda <carlhuda@engineyard.com> | 2010-02-26 15:20:41 -0800 |
---|---|---|
committer | Carlhuda <carlhuda@engineyard.com> | 2010-02-26 15:20:41 -0800 |
commit | bae691f61ab8cf4a59adaee6406855e11d009c74 (patch) | |
tree | 30dbf62a2f8cce56498fc8d92b35a2d5ff0a66a8 /actionpack/lib/action_dispatch/routing | |
parent | 224c0318bdbaea354bc5ab5c70b267b2a9c3d1c9 (diff) | |
download | rails-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.
Diffstat (limited to 'actionpack/lib/action_dispatch/routing')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/url_for.rb | 34 |
1 files changed, 23 insertions, 11 deletions
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 |