提交 bae691f6 编写于 作者: C Carlhuda

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.
上级 224c0318
......@@ -5,7 +5,7 @@ module UrlFor
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,
......
......@@ -336,7 +336,7 @@ def rescue_action_in_public!
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)
......
......@@ -95,22 +95,26 @@ module UrlFor
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 @@ def url_for(options = {})
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
......
......@@ -357,7 +357,7 @@ def copy_session_variables! #:nodoc:
extend ActiveSupport::Concern
include ActionDispatch::Routing::UrlFor
def merge_options(options)
def url_options
opts = super.reverse_merge(
:host => host,
:protocol => https? ? "https" : "http"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册