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 url. Used to redirect outside of the current application. Example: - # redirect_to_url "http://www.rubyonrails.org". - def redirect_to_url(url) #:doc: + # redirect_to_url "http://www.rubyonrails.org". 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