diff options
author | Michael Koziarski <michael@koziarski.com> | 2008-06-23 19:46:15 +0300 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2008-07-04 10:41:40 +0300 |
commit | c3aaba0180f0710094d974b4ba4659bce81446df (patch) | |
tree | bed34c6b4caa1952dabba71af6f95dae02322af4 /actionpack/lib/action_controller/base.rb | |
parent | db5839107951b000633fa8405f78e5c315b6656a (diff) | |
download | rails-c3aaba0180f0710094d974b4ba4659bce81446df.tar.gz rails-c3aaba0180f0710094d974b4ba4659bce81446df.tar.bz2 rails-c3aaba0180f0710094d974b4ba4659bce81446df.zip |
Simplify the implementation of assert_redirected_to to normalise the urls before comparing. Also allows for a simpler implementation of redirect_to without most of the recursion.
Also allows for assert_redirected_to @some_record
Diffstat (limited to 'actionpack/lib/action_controller/base.rb')
-rwxr-xr-x | actionpack/lib/action_controller/base.rb | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index a4bade1bd5..58eb5cabcd 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -1042,29 +1042,31 @@ module ActionController #:nodoc: status = 302 end + response.redirected_to= options + logger.info("Redirected to #{options}") if logger && logger.info? + case options when %r{^\w+://.*} - raise DoubleRenderError if performed? - logger.info("Redirected to #{options}") if logger && logger.info? - response.redirect(options, interpret_status(status)) - response.redirected_to = options - @performed_redirect = true - + redirect_to_full_url(options, status) when String - redirect_to(request.protocol + request.host_with_port + options, :status=>status) - + redirect_to_full_url(request.protocol + request.host_with_port + options, status) when :back - request.env["HTTP_REFERER"] ? redirect_to(request.env["HTTP_REFERER"], :status=>status) : raise(RedirectBackError) - - when Hash - redirect_to(url_for(options), :status=>status) - response.redirected_to = options - + if referer = request.headers["Referer"] + redirect_to(referer, :status=>status) + else + raise RedirectBackError + end else - redirect_to(url_for(options), :status=>status) + redirect_to_full_url(url_for(options), status) end end + def redirect_to_full_url(url, status) + raise DoubleRenderError if performed? + response.redirect(url, interpret_status(status)) + @performed_redirect = true + end + # Sets a HTTP 1.1 Cache-Control header. Defaults to issuing a "private" instruction, so that # intermediate caches shouldn't cache the response. # |