I wanted to find the best way to handle errors in rails, so my code is easy to read and my tests too.
Firstly, I created an errors.rb file in the /lib folder.
At the top of my application_controller.rb I loaded that file (require ‘errors’). Then in my application controller I added the code below to rescue from my exceptions.
Now I can raise an exception in my controllers like so:
This is really easy to test, using mini test.
Finally I just need to make my error pages look good.