Module: HTTPStatus
- Defined in:
- lib/http_status_exceptions.rb
Defined Under Namespace
Classes: Base
Class Method Summary collapse
-
.included(base) ⇒ Object
Creates all the exception classes based on Rails’s list of available status code and registers the exception handler using the rescue_from method.
Instance Method Summary collapse
-
#http_status_exception(exception) ⇒ Object
The default handler for raised HTTP status exceptions.
Class Method Details
.included(base) ⇒ Object
Creates all the exception classes based on Rails’s list of available status code and registers the exception handler using the rescue_from method.
31 32 33 34 35 36 37 |
# File 'lib/http_status_exceptions.rb', line 31 def self.included(base) ActionController::StatusCodes::STATUS_CODES.each do |code, name| const_set("#{name.to_s.gsub(/[^A-z]/, '').camelize}", Class.new(HTTPStatus::Base)) end base.send(:rescue_from, HTTPStatus::Base, :with => :http_status_exception) end |
Instance Method Details
#http_status_exception(exception) ⇒ Object
The default handler for raised HTTP status exceptions. It will render a template if available, or respond with an empty response with the HTTP status correspodning to the exception.
42 43 44 45 46 47 |
# File 'lib/http_status_exceptions.rb', line 42 def http_status_exception(exception) @exception = exception render(:template => exception.template, :status => exception.status) rescue ActionView::MissingTemplate head(exception.status) end |