Rexception is a Rails plugin that renders error pages dynamically, such as 403, 404, 500, and so on.
Add this line to your application's Gemfile:
gem 'rexception'
And then execute:
$ bundle
The simplest way, just add app/views/errors/application.html.erb
.
That's it, and Rails application render it when raise any errors.
If you placed specific views, such as forbidden.html.erb
or not_found.html.erb
, Rexception prefers these views to application.html.erb
.
(File name is see also: ActionDispatch::ExceptionWrapper.rescue_responses)
And you can specify layout file name, directory name to place views, and custom exceptions.
Create config/initializers/rexception.rb
and add following lines:
Rexception.configure do |config|
# Layout file name to use for rendering error page.
config.layout = 'application'
# Directory name where you place error pages.
config.errors_dir = 'errors_dir'
# Pairs of custom exceptions and statuses.
config.rescue_responses = {
'CustomException' => :not_found
}
end
In development
mode, you should add this line to config/environments/development.rb
to render error pages:
config.consider_all_requests_local = false
- Fork it ( https://github.com/kami-zh/rexception/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request