Module: Applicat::Mvc::Controller::ErrorHandling
- Defined in:
- lib/applicat/mvc/controller/error_handling.rb
Defined Under Namespace
Classes: NoPermissionError
Class Method Summary collapse
-
.included(base) ⇒ Object
include Applicat::Errors.
Class Method Details
.included(base) ⇒ Object
include Applicat::Errors
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/applicat/mvc/controller/error_handling.rb', line 7 def self.included(base) if Rails.env != 'development' base.class_eval do rescue_from Applicat::Mvc::Controller::ErrorHandling::NoPermissionError do |e| response_for_error 403 end rescue_from ActiveRecord::RecordNotFound do |e| response_for_error 404 end private def response_for_error(status) respond_to do |f| # Show a neat html page inside the app's layout for web users f.html { render :template => "errors/#{status}", :status => status } # Everything else (JSON, XML, YAML, Whatnot) gets a blank page with status # which can then be understood and processed by the API client, # JavaScript library (on Ajax) etc. f.all { render :nothing => true, :status => status } end end end end end |