Search code examples
ruby-on-railsexceptionruby-on-rails-3.2actioncontroller

rescue_from ::AbstractController::ActionNotFound not working


I have the following code:

unless Rails.application.config.consider_all_requests_local
  rescue_from Exception, with: :render_exception
  rescue_from ActiveRecord::RecordNotFound, with: :render_exception
  rescue_from ActionController::UnknownController, with: :render_exception
  rescue_from ::AbstractController::ActionNotFound, with: :render_exception
  rescue_from ActiveRecord::ActiveRecordError, with: :render_exception
  rescue_from NoMethodError, with: :render_exception
end

They all work flawless, except ::AbstractController::ActionNotFound

I've also tried

AbstractController::ActionNotFound
ActionController::UnknownAction

error:

   AbstractController::ActionNotFound (The action 'show' could not be found for ProductsController):

Solution

  • This similar question suggests that you can no longer catch an ActionNotFound exception. Check the link for workarounds. This suggestion to use a Rack middleware to catch 404s looks the cleanest to me.