Skip to content

Instantly share code, notes, and snippets.

@jenny-codes
Created February 9, 2019 09:51
Show Gist options
  • Save jenny-codes/02e78aab3f08403ac7ec16ad0f784a15 to your computer and use it in GitHub Desktop.
Save jenny-codes/02e78aab3f08403ac7ec16ad0f784a15 to your computer and use it in GitHub Desktop.
# 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