diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-31 17:04:15 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-31 17:04:15 +0000 |
commit | 2e1a27fa4de4460808405bdb7771ae2c59b99dd1 (patch) | |
tree | 499655b2ac5a0402045df0bcae2210d10561eeb0 /actionpack | |
parent | 9a5321fccfa95719732eec664f5d2f25e5e6cde4 (diff) | |
download | rails-2e1a27fa4de4460808405bdb7771ae2c59b99dd1.tar.gz rails-2e1a27fa4de4460808405bdb7771ae2c59b99dd1.tar.bz2 rails-2e1a27fa4de4460808405bdb7771ae2c59b99dd1.zip |
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
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rwxr-xr-x | actionpack/lib/action_controller/base.rb | 7 | ||||
-rwxr-xr-x | actionpack/lib/action_controller/response.rb | 4 |
3 files changed, 8 insertions, 5 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 4c5365f032..8793797a94 100644 --- a/actionpack/CHANGELOG +++ b/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. diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 82daf608c6..6d9278266d 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -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 diff --git a/actionpack/lib/action_controller/response.rb b/actionpack/lib/action_controller/response.rb index 836dd5ffef..a574fbca75 100755 --- a/actionpack/lib/action_controller/response.rb +++ b/actionpack/lib/action_controller/response.rb @@ -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 |