diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-01-22 01:52:23 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-01-22 01:52:23 +0000 |
commit | ea30f7353be3a977c5ea50d8efaa02acf26dd133 (patch) | |
tree | c59554a191f1f0f1362adf310952db00ba25ceb6 /actionpack/lib/action_controller/base.rb | |
parent | 039a90f535f8d80d02cabe79a297275977939b10 (diff) | |
download | rails-ea30f7353be3a977c5ea50d8efaa02acf26dd133.tar.gz rails-ea30f7353be3a977c5ea50d8efaa02acf26dd133.tar.bz2 rails-ea30f7353be3a977c5ea50d8efaa02acf26dd133.zip |
Raise a RedirectBackError if redirect_to :back is called when theres no HTTP_REFERER defined (closes #3049) [kevin.clark@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3459 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/base.rb')
-rwxr-xr-x | actionpack/lib/action_controller/base.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 8a34cd18cf..0a9368f684 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -40,6 +40,13 @@ module ActionController #:nodoc: super(message || DEFAULT_MESSAGE) end end + class RedirectBackError < ActionControllerError #:nodoc: + DEFAULT_MESSAGE = 'No HTTP_REFERER was set in the request to this action, so redirect_to :back could not be called successfully. If this is a test, make sure to specify @request.env["HTTP_REFERER"].' + + def initialize(message = nil) + super(message || DEFAULT_MESSAGE) + end + end # Action Controllers are made up of one or more actions that performs its purpose and then either renders a template or # redirects to another action. An action is defined as a public method on the controller, which will automatically be @@ -780,7 +787,7 @@ module ActionController #:nodoc: redirect_to(request.protocol + request.host_with_port + options) when :back - redirect_to(request.env["HTTP_REFERER"]) + request.env["HTTP_REFERER"] ? redirect_to(request.env["HTTP_REFERER"]) : raise(RedirectBackError) else if parameters_for_method_reference.empty? |