Skip to content

Users always make mistakes ad we have to explain them in a better way what did they do wrong.

License

Notifications You must be signed in to change notification settings

ifad/user_error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

User Error

Display better errors on rails apps with bootstrap.

How to use it

Add to your Gemfile

gem 'user_error'

How to configure it

The engine will catch every exception defined in the ActionDispatch::ExceptionWrapper middleware and set up an exceptions_app to handle them.

To make it catch your custom exceptions, create a new initializer in config/initializers with the following contents:

UserError.configure do
  rescue_from 'My::Exception', :with => :forbidden
end

An initializer will help you on that, if you want. Just execute

railg g user_error:install

e.g. for CanCan:

UserError.configure do
  rescue_from 'CanCan::AccessDenied', :with => :forbidden
end

The :with value will define the HTTP status code of the response, as defined in Rack::Utils, and it will also be an I18n namespace to customize the messages.

If you want to customize the UserError controller, do it in a controller block. E.g. if you have an :authenticate callback in your ApplicationController but you do not want the exception display to require :authenticate, you could do:

UserError.configure do
  controller do
    skip_before_filter :authenticate
  end
end

Of course, make sure that your application layout can deal with a current_user being nil.

Contributing

  1. Fork the repository on Github
  2. Create a named feature branch (like add_component_x)
  3. Write you change
  4. Write tests for your change (if applicable)
  5. Run the tests, ensuring they all pass
  6. Submit a Pull Request using Github

Developers

Lleir Borras http://github.com/lleirborras

Marcello Barnaba http://github.com/vjt

Denominazione d'Origine Controllata

This software is Made in Italy 🇮🇹 😄.

About

Users always make mistakes ad we have to explain them in a better way what did they do wrong.

Resources

License

Stars

Watchers

Forks

Packages

No packages published