# config/environments/production.rb
config.exceptions_app = ErrorController.action(:handle)
# app/controllers/error_controller.rb
class ErrorController
def handle
flash.alert(t(".message"))
redirect_to :back
end
end
# config/application.rb
config.exceptions_app = self.routes
# config/routes.rb
match '/404', via: :all, to: 'errors#not_found'
match '/422', via: :all, to: 'errors#unprocessable_entity'
match '/500', via: :all, to: 'errors#server_error'
# app/controllers/errors_controller.rb
class ErrorsController < ActionController::Base
layout 'error'
def not_found
render status: :not_found
end
def unprocessable_entity
render status: :unprocessable_entity
end
def server_error
render status: :server_error
end
end
# app/views
errors/
not_found.html.erb
unprocessable_entity.html.erb
server_error.html.erb
layouts/
error.html.erb