Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
The new way of showing/rendering all exceptions in Rails 3.2+
# put this in an initializer
# a Rails 3.2 addendum for:
class MyShowExceptions
def initialize()
@@rescue_responses =
'ActionController::RoutingError' => :not_found,
'AbstractController::ActionNotFound' => :not_found,
'ActiveRecord::RecordNotFound' => :not_found,
'ActiveRecord::StaleObjectError' => :conflict,
'ActiveRecord::RecordInvalid' => :unprocessable_entity,
'ActiveRecord::RecordNotSaved' => :unprocessable_entity,
'ActionController::MethodNotAllowed' => :method_not_allowed,
'ActionController::NotImplemented' => :not_implemented,
'ActionController::InvalidAuthenticityToken' => :unprocessable_entity,
'ArgumentError' => :unprocessable_entity
def call(env)
exception = env["action_dispatch.exception"] ||
body = ErrorsController.action(@@rescue_responses[]).call(env)
# Configure ShowExceptions and pass the only instance of above class to it
Rails.configuration.middleware.use "ActionDispatch::ShowExceptions",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment