提交 2090615d 编写于 作者: A Aaron Patterson

refactor Redirecting so we do not need a controller instance

上级 3dfcae6a
......@@ -72,11 +72,11 @@ def redirect_to(options = {}, response_status = {}) #:doc:
raise AbstractController::DoubleRenderError if response_body
self.status = _extract_redirect_to_status(options, response_status)
self.location = _compute_redirect_to_location(options)
self.location = _compute_redirect_to_location(request, options)
self.response_body = "<html><body>You are being <a href=\"#{ERB::Util.unwrapped_html_escape(location)}\">redirected</a>.</body></html>"
end
def _compute_redirect_to_location(options) #:nodoc:
def _compute_redirect_to_location(request, options) #:nodoc:
case options
# The scheme name consist of a letter followed by any combination of
# letters, digits, and the plus ("+"), period ("."), or hyphen ("-")
......@@ -90,11 +90,13 @@ def _compute_redirect_to_location(options) #:nodoc:
when :back
request.headers["Referer"] or raise RedirectBackError
when Proc
_compute_redirect_to_location options.call
_compute_redirect_to_location request, options.call
else
url_for(options)
end.delete("\0\r\n")
end
module_function :_compute_redirect_to_location
public :_compute_redirect_to_location
private
def _extract_redirect_to_status(options, response_status)
......
......@@ -73,13 +73,8 @@ def normalize_argument_to_redirection(fragment)
if Regexp === fragment
fragment
else
handle = @controller || Class.new(ActionController::Metal) do
include ActionController::Redirecting
def initialize(request)
@_request = request
end
end.new(@request)
handle._compute_redirect_to_location(fragment)
handle = @controller || ActionController::Redirecting
handle._compute_redirect_to_location(@request, fragment)
end
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册