Skip to content

Commit

Permalink
Added second boolean parameter to Base.redirect_to_url and Response#r…
Browse files Browse the repository at this point in the history
…edirect to control whether the redirect is permanent or not (301 vs 302) rails#375 [Hodel]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@293 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Dec 31, 2004
1 parent 9a5321f commit 2e1a27f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -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.
Expand Down
7 changes: 4 additions & 3 deletions actionpack/lib/action_controller/base.rb
Expand Up @@ -529,10 +529,11 @@ def redirect_to_path(path) #:doc:
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

Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_controller/response.rb
Expand Up @@ -7,8 +7,8 @@ def initialize
@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
Expand Down

0 comments on commit 2e1a27f

Please sign in to comment.