No commit activity in last 3 years
No release in over 3 years
Custom Errors Handler is intended as an easy alternative to manage showing/rendering exceptions templates (404, 500) in Rails3
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 3.0.0
>= 2.0.0
 Project Readme

CustomErrorsHandler

Install

gem install custom_error_handler

and in your Gemfile:

gem 'custom_error_handler'

and in your test.rb remove (or hide):

config.action_dispatch.show_exceptions = false

About

Custom Errors Handler is intended as an easy alternative to manage showing/rendering exceptions templates (404, 500) in Rails3.

The intent behind it was to KISS as much as it is possible. It allows you to render different 404/500 templates for different controllers/modules. If no errors templates are found, it renders default public/error_code template. It works only with Rails3 and it integrates to its middleware, swapping with default ActionDispatch::ShowExceptions.

Usage

The basics of Custom Errors Handler are quite simple:

It fetches all errors comming from controllers and it decides frm which file Rails should render error.

It search throught all the directories from the place where error occured, up to views root path.

It also checks in subdir "template" in any subdir.

Example

First easy one:

Error 404 (not found) occurred in controller ErrorMakingController.

Custom Errors Handler searches for template called "404.erb" in following directories:

/views/layouts/error_making/errors
/views/layouts/error_making/
/views/layouts/
/views/

After it find template - it just render it.

Controller in Module:

Error 500 occurred in controller MyModule::ErrorMakingController in action index.

Our Custom Errors Handler searches in (searches for "500.erb"):

/views/layouts/my_module/error_making/errors
/views/layouts/my_module/error_making/
/views/layouts/my_module/
/views/layouts/my_module/
/views/layouts/
/views/

So as you can see you can use different error templates for both controllers and modules.

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright (c) 2011 Maciej Mensfeld. See LICENSE for details.