
Handling Rails errors: custom error pages, logging, notification
I wanted to improve error handling In my Rails applications. Specifically, I wanted three things:
- a custom error page that matched the site's design
- the errors to appear in the error log (production.log)
- email notification of server errors
Note: these steps are for Rails 2.3.2–2.3.8. Other versions may require different instructions.
Custom error page
Normally, when server error occurs, Rails renders public/500.html. You can customize this. However, if you include your site's layout information here, you violate the DRY principle.
- Create a directory for error templates
mkdir app/views/errors - Create the error file:
touch app/views/errors/500.html.erb - Remove the static file:
rm public/500.html - In
application_controller.rb, overriderender_optional_error_file:protected def render_optional_error_file(status_code) render :template => "errors/500", :status => 500, :layout => 'application' end
- To test your error handler in the development environment, in
application_controller.rb, add this line:alias_method :rescue_action_locally, :rescue_action_in_publicbe sure to comment this out when you're done, so you can see backtraces.
Logging errors
Because we overrode render_optional_error_file instead of using rescue_from (2), errors still go to the log (production.log).
Email notification
There's a terrific exception notification plugin that handles this for you.
This is a bit confusing, because there are three versions of the plugin floating around:
- The master version on github, for Rails 3
- A branch on github, for Rails 2.3
- The old version, which also works with Rails 2
Important If you install via the standard method (script/plugin install), you'll get an old version of the plugin, and the current instructions (on github) won't work. (See below for legacy instructions.)
If you install from github, you'll get a version for Rails 3 by default, and that won't work, either.
Here's what to do:
- Install the plugin from the 2-3-stable branch from github:
script/plugin install git://github.com/rails/exception_notification.git -r 2-3-stable - In
application_controller.rb, place this at the top:include ExceptionNotification::Notifiable - In
environment.rb, add these lines at the very end, after the|config|block:ExceptionNotification::Notifier.exception_recipients = %w([email protected]) ExceptionNotification::Notifier.sender_address = %("Application Error" <[email protected]>) ExceptionNotification::Notifier.email_prefix = "[Fancy App] "
-
To have sendmail send email (instead of using raw SMTP), add this line to
environment.rb:ActionMailer::Base.delivery_method = :sendmail
Legacy exception_notification instructions
- Install the plugin:
script/plugin install exception_notification - In
application_controller.rb, place this at the top:include ExceptionNotifiable - In
environment.rb, add these lines at the very end, after the|config|block:ExceptionNotifier.exception_recipients = %w([email protected]) ExceptionNotifier.sender_address = %("Application Error" <[email protected]>) ExceptionNotifier.email_prefix = "[Fancy App] "
Bikes on a plane
When I went to New Zealand last year, I decided to take my bike with me. I’d have a van the whole time, so moving it around with me would be easy. And Air New Zealand allowed me two free bags, one of which could be a bicycle.
If you’re interested in travelling with your bicycles, here’s what it will cost you:
Packing the bicycle
Before you can take your bike on a plane, you need to pack it in a bike box. Almost any bike shop will give you one of these for free. There are many YouTube videos teaching you how to box up your bicycle.
Aside: If you have an expensive bike or are planning to travel with your bike a lot, it’s worth investing in a hard case.
If you don’t want to pack the bike yourself, you can pay a bike shop to do this for you.
Bike shops in San Francisco
I called many of the bike shops in San Francisco. Here’s what they charge to box up a bike, sorted by price:
| Shop | Price |
|---|---|
| Warm Planet BIkes | $35-40 |
| Sports Basement | $45 ($30-60) |
| Valencia Cyclery | $45 |
| The Freewheel | $50 |
| Lombardi Sports | $50 |
| Pacific Bicycle | $50 |
| REI | $60 |
| Box Dog Bikes | $70 |
| American Cyclery | $70–85 |
| Performance Bike | $100 |
| Mike’s Bikes | $100 |
| Mission Bicycle Company | — |
| Pedal Revolution | — |
| Roaring Mouse | — |
I’m not sure what Mike’s and Performance do for $100. Maybe they use gold tape on the box.
Bike shops in Auckland
Here’s what the bike shops in Auckland charge:
| Shop | Price (NZD) | USD equivalent |
|---|---|---|
| Bike Barn | $35–40 | $25–28 |
| Hedgehog Bikes | $40–50 | $28-36 |
Airlines
Once your bike is all packed up, the airline may charge you another fee to accept the bicycle as a checked bag. This table’s sorted by airline name:
| Airline | Fee | Notes | |
|---|---|---|---|
| Air Canada | $50 | ||
| Air New Zealand | free | ||
| AirTran | $79 | ||
| Alaska/Horizon | free | ||
| American Airlines | $100 | 2 | |
| Continental | $100 | 2 | |
| Delta | $200 | ||
| Frontier | $50 | 2 | |
| Hawaiian | $100 | 3 | |
| JetBlue | $50 | 2 | |
| Midwest | $50 | ||
| Qantas | free | ||
| Spirit | $75 | ||
| US Air | $100 | 2 | |
| United | $100 | ||
| V Australia | free | ||
| Virgin America | $50 | ||
| Virgin Atlantic | free | ||
| Virgin Blue/Pacific Blue | $20 | 1 | |
| WestJet | free |
Notes
[1] Included in your standard (paid) baggage allowance (cost is $20)
[2] Small bikes (measuring under 62 “dimensional” or “linear” inches) are free (included in your baggage allowance)
[3] $35 for flights within Hawaii
What Mark Fiore is doing with his Pulitzer Prize money
Newly minted Pulitzer Prize winner Mark Fiore — whose app is now in the iTunes Store — had this to say:
Since winning the prize brought attention to Apple’s policy of rejecting iPhone apps that “ridicule public figures” I figure the least I can do is devote more resources to ridiculing public figures.”
More app store hypocrisy
Earlier this year, the nuns on Cupertino’s app store approval team removed 5000 applications for having sexual content. Fine. Be a prude. But what makes this funny is that Apple’s left hand doesn’t know what its right hand is doing: the music store will sell you D12’s Nasty Mind, which contains lyrical gems such as this:
Hoe you can quote this – your breath is smellin like
you done sucked a senior citizen’s old dick in goat spit (god damn!)
It’s one thing to be a prude. It’s another thing to be a homophobic prude. How are eight different apps for locating strip clubs is okay, but a a gay sightseeing guide isn’t?
UPS = United Parcel Storage
How does it make sense for UPS to keep my package in a warehouse — 19 miles from my house — for two days?

Ride Snowboards’ phone number
To reach Ride Snowboards’ customer service, call their parent company, K2 Sports at (206) 805-4800‎.
Then push 1 (for customer service), 2 (for snowboards), 2 (for Ride) and 2 (for consumers).
Don’t cancel
Liz Danzico wrote a great little essay on two flaws in our culture:
- Saying things we don’t mean to be “polite” (“Let’s get together soon”)
- Agreeing to do something and then cancelling on the person
The post is concise and thoughtful — read the whole thing — and concludes with this:
4. Don’t cancel
Ever.Next time you’re tempted to cancel, do the opposite. See what happens if you show up instead. You might just change culture.
Try it.
There’s a reason he was denied bail
From the January 9, 2010 Herald Sun:

Facebook doesn’t understand Canada
When you update your Facebook account and link your interests and activities to the new community pages, Facebook automatically assigns a picture to represent each interest.
Sometimes that doesn’t work very well:
