When you are developing rails apps and you are hacking your way around, it is fine to get a bunch of errors and screen dump of what went wrong. However, when you start deploying it and want to convince users to accept the new system exceptions are like segfaults. You do not want them to see gobs of exception messages on their browser which will be an excuse for them to write it off even if they did not RTM and did something wrong. Another problem is that people will happily hit Back and not save what happened and only bitch about the instability of the system.
Exception Notifier is a great plugin to solve these issues. Basic installation of the plugin is pretty smooth and if you already have emails working from your app then exception notification works pretty easily. There are enough Google results for you to get it working.
One standard problem that almost everyone has is to get it working in your development environment. The following changes did it for me: update your application.rb and update your config/environment/development.rb.
application.rb
include ExceptionNotifiable
local_addresses.clear
development.rb
config.action_controller.consider_all_requests_local = false
More interesting changes are to do with picking specific errors out of all the errors and sending some to the browser and some via email. In my case, I had support for free-form SQL queries in our internal application which could give internal MySQL errors to user queries which I wanted to go to the browser. Here is what you add to application.rb:
# Try to get incorrect SQL errors and show them on screen
def rescue_action_in_public(exception)
case exception
when ActiveRecord::StatementInvalid
render :text => "You have errors in your SQL Syntax. Please try the Back button and fix them before trying again. #{exception.message.inspect}"
when ActiveRecord::MultiparameterAssignmentErrors
render :text => "You seem to have some inconsistent input. e.g. Date like Feb 30 2007. Please try the Back button and fix them before trying again. #{exception.message.inspect}"
else
super
end
end
The ActiveRecord::MultiparameterAssignmentErrors is a very interesting exception which you surely want to get to the user than via an email to the admin. I found out that when forms have incorrect date input (like Feb 31), MySQL generates this obscure exception. I could have borrowed some date validation code but why do extra work when you can rap the users knuckles instead.