Module: ActionController::Rescue
- Defined in:
- lib/action_controller/rescue.rb
Overview
Actions that fail to perform as expected throw exceptions. These exceptions can either be rescued for the public view (with a nice user-friendly explanation) or for the developers view (with tons of debugging information). The developers view is already implemented by the Action Controller, but the public view should be tailored to your specific application.
The default behavior for public exceptions is to render a static html file with the name of the error code thrown. If no such file exists, an empty response is sent with the correct status code.
You can override what constitutes a local request by overriding the local_request?
method in your own controller. Custom rescue behavior is achieved by overriding the rescue_action_in_public
and rescue_action_locally
methods.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- LOCALHOST =
'127.0.0.1'.freeze
- DEFAULT_RESCUE_RESPONSE =
:internal_server_error
- DEFAULT_RESCUE_RESPONSES =
{ 'ActionController::RoutingError' => :not_found, 'ActionController::UnknownAction' => :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 }
- DEFAULT_RESCUE_TEMPLATE =
'diagnostics'
- DEFAULT_RESCUE_TEMPLATES =
{ 'ActionView::MissingTemplate' => 'missing_template', 'ActionController::RoutingError' => 'routing_error', 'ActionController::UnknownAction' => 'unknown_action', 'ActionView::TemplateError' => 'template_error' }
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Class Method Details
.included(base) ⇒ Object
:nodoc:
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/action_controller/rescue.rb', line 35 def self.included(base) #:nodoc: base.cattr_accessor :rescue_responses base.rescue_responses = Hash.new(DEFAULT_RESCUE_RESPONSE) base.rescue_responses.update DEFAULT_RESCUE_RESPONSES base.cattr_accessor :rescue_templates base.rescue_templates = Hash.new(DEFAULT_RESCUE_TEMPLATE) base.rescue_templates.update DEFAULT_RESCUE_TEMPLATES base.extend(ClassMethods) base.send :include, ActiveSupport::Rescuable base.class_eval do alias_method_chain :perform_action, :rescue end end |