Module: SimpleErrors::Rescue
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/simple_errors/rescue.rb
Overview
A mixin for ApplicationController which rescues from common errors. If you have specific ones you want to rescue with a 404, call the class method rescue_with_not_found, passing one or more error classes
Instance Method Summary collapse
- #call_before_rescue_block ⇒ Object
- #render_error(exception = nil) ⇒ Object
- #render_not_found(exception = nil) ⇒ Object
Instance Method Details
#call_before_rescue_block ⇒ Object
74 75 76 77 78 |
# File 'lib/simple_errors/rescue.rb', line 74 def call_before_rescue_block if defined?(@@before_rescue) && @@before_rescue.is_a?(Proc) instance_eval(&@@before_rescue) end end |
#render_error(exception = nil) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/simple_errors/rescue.rb', line 61 def render_error(exception = nil) call_before_rescue_block @exception = exception respond_to do |format| format.html do render 'errors/500', status: 500, layout: 'layouts/error' end format.all do render nothing: true, status: 500 end end end |
#render_not_found(exception = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/simple_errors/rescue.rb', line 48 def render_not_found(exception = nil) call_before_rescue_block @exception = exception respond_to do |format| format.html do render 'errors/404', status: 404, layout: "layouts/error" end format.all do render nothing: true, status: 404 end end end |