As part of my work on Shapado in the Google Summer of Code, I just released a Rails3-compatible little gem (called Goalie) that makes it easy to have custom error pages with dynamic content. It is still very early-stages and I would like your feedback. Here’s the release README. Enjoy!
Goalie
Goalie is a flexible dynamic error response renderer for
Rails built on Rack and Rails Engines. It provides the same
default error pages as Rails, but allows you to easily customize
them with dynamic content. This means you can use your
application layout, have different error pages for different
subdomains, and do all sorts nice things.
Installation
WARNING: at this point, Goalie is highly experimental and
should not be used in production!! Everything can and probably
will change before it is ready for production. Install it only if
you want to play with and/or contribute to it.
gem install goalie
After you install it and add it to your Gemfile , you have to require it together with Rails’ frameworks
at the top of your config/application.rb file:
require 'goalie/rails'
This will remove Rails’ default exception renderer middleware
( ShowExceptions ) and use Goalie’s
instead. Unless you have custom static pages in your directory (which we plan to support later), this
public
will be a drop-in replacement.
Customization
Controllers
The public (production) rescuing of errors is done by the
PublicErrorsController found in Goalie’s directory. If you create a controller
app/controllers
with the same name, it will automatically be used instead of
Goalie’s. All it needs to do is support the following actions:
internal_server_error-
not_found -
unprocessable_entity -
conflict -
method_not_allowed -
not_implemented
If you don’t actually need a separate action for each of
these errors, you can redirect them to others, for example, with:
def unprocessable_entity
render :action => 'internal_server_error'
end
Views
You can also customize only the views and use Goalie’s
default controller. All you need is to have inside views with the same names as the
app/views/public_errors
actions listed above. Besides the standard stuff that Rails makes
available to views, you will also have access to the following
instance variables:
Be VERY careful when using this in production, as you could
expose sensitive information inside the request and
exception. Generally, you probably shouldn’t use these variables
at all. The only place it makes sense is to have a more detailed
error screen for admins or other high-level users.
Credit
Goalie copies a lot of code and ideas from:
* Rails’ ShowExceptions middleware
* Rails’ default error views
* Rails’ exception_notification plugin
Which are mostly the work of
Joshua Peek , with help from various contributors. We’re
highly indebted to them and thank them a lot for their work.
Contributions
Any form of feedback, patches, issues, and documentation are
highly appreciated.
License
MIT license. Copyright 2010 Helder Ribeiro.

