1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Added second boolean parameter to Base.redirect_to_url and Response#redirect to control whether the redirect is permanent or not (301 vs 302) #375 [Hodel]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@293 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2004-12-31 17:04:15 +00:00
parent 9a5321fccf
commit 2e1a27fa4d
3 changed files with 8 additions and 5 deletions

View file

@ -1,5 +1,7 @@
*SVN*
* Added second boolean parameter to Base.redirect_to_url and Response#redirect to control whether the redirect is permanent or not (301 vs 302) #375 [Hodel]
* Fixed that @request.remote_ip didn't work in the test environment #369 [Bruno Mattarollo]
* Added :host and :protocol options to url_for and friends to redirect to another host and protocol than the current.

View file

@ -529,10 +529,11 @@ module ActionController #:nodoc:
end
# Redirects the browser to the specified <tt>url</tt>. Used to redirect outside of the current application. Example:
# <tt>redirect_to_url "http://www.rubyonrails.org"</tt>.
def redirect_to_url(url) #:doc:
# <tt>redirect_to_url "http://www.rubyonrails.org"</tt>. If the resource has moved permanently, it's possible to pass true as the
# second parameter and the browser will get "301 Moved Permanently" instead of "302 Found".
def redirect_to_url(url, permanently = false) #:doc:
logger.info("Redirected to #{url}") unless logger.nil?
@response.redirect(url)
@response.redirect(url, permanently)
@performed_redirect = true
end

View file

@ -7,8 +7,8 @@ module ActionController
@body, @headers, @session, @assigns = "", DEFAULT_HEADERS.merge("cookie" => []), [], []
end
def redirect(to_url)
@headers["Status"] = "302 Moved"
def redirect(to_url, permanently = false)
@headers["Status"] = permanently ? "301 Moved Permanently" : "302 Found"
@headers["location"] = to_url
end
end