Cannot catch ActionController exception

Hi,

I am running ruby 1.8.2
(ruby 1.8.2 (2005-04-11) [i386-linux])

I cannot catch the ActionController::RedirectBackError exception.

My code is:

       begin
         redirect_to :back
       rescue ActionController::RedirectBackError
         redirect_to :action => 'index'
       end

When the exception is raised I get the following error:

NameError in Release managementController#new

uninitialized constant RedirectBackError

RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace

/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:123:in
`const_missing'
#{RAILS_ROOT}/app/controllers/release_management_controller.rb:821:in
`new'

/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:123:in
`const_missing'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in
`send'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in
`perform_action_without_filters'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:368:in
`perform_action_without_benchmark'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in
`measure'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/rescue.rb:82:in
`perform_action'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in
`send'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in
`process_without_filters'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in
`process_without_session_management_support'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:in
`process'
/usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in
`dispatch'
/usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:115:in
`handle_dispatch'
/usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:81:in
`service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:172:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:161:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:161:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
/usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:67:in
`dispatch'
script/server:49

/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:123:in
`const_missing'
#{RAILS_ROOT}/app/controllers/release_management_controller.rb:821:in
`new'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in
`send'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in
`perform_action_without_filters'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:368:in
`perform_action_without_benchmark'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in
`measure'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/rescue.rb:82:in
`perform_action'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in
`send'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in
`process_without_filters'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in
`process_without_session_management_support'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:in
`process'
/usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in
`dispatch'
/usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:115:in
`handle_dispatch'
/usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:81:in
`service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:172:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:161:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:161:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
/usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:67:in
`dispatch'
script/server:49

This error occured while loading the following files:

action_web_service/dispatcher/action_controller/redirect_back_error.rb

If I change the code to catch all exceptions then it works, but I would
prefer not to do this.

Thanks

joman wrote:

I cannot catch the ActionController::RedirectBackError exception.

My code is:

       begin
         redirect_to :back
       rescue ActionController::RedirectBackError
         redirect_to :action => 'index'
       end

When the exception is raised I get the following error:

NameError in Release managementController#new

uninitialized constant RedirectBackError

Change the rescue to

rescue ::ActionController::RedirectBackError

That's it! Thanks very much.

Mark Reginald James wrote: