You can also define a rescue_from method.
class ApplicationController < ActionController::Base rescue_from ActionController::RoutingError, :with => :error_render_method def error_render_method respond_to do |type| type.xml { render :template => "errors/error_404", :status => 404 } type.all { render :nothing => true, :status => 404 } end true end end
Depending on your purpose, you may also consider the possibility of handling exceptions for each controller. Instead, use something like exception_handler to sequentially manage exception responses. As a bonus, this approach will also handle exceptions that occur at the middleware level, such as parsing queries or database connection errors that your application does not see. The stone exception_notifier may also be of interest.
BOFH Jul 21 2018-11-11T00: 00Z
source share