Created
February 9, 2019 09:51
-
-
Save jenny-codes/02e78aab3f08403ac7ec16ad0f784a15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Error module to Handle errors globally | |
# include Error::ErrorHandler in application_controller.rb | |
module Error | |
module ErrorHandler | |
def self.included(clazz) | |
clazz.class_eval do | |
rescue_from StandardError, with: :standard_error | |
end | |
end | |
private | |
def standard_error(_e) | |
flash[:danger] = "Oops! #{_e}" | |
redirect_to list_posts_path | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
reference
https://medium.com/rails-ember-beyond/error-handling-in-rails-the-modular-way-9afcddd2fe1b