First set up a simple errors controller:
class ErrorsController < ApplicationController def missing_page render :status => :not_found end end
The view for missing_page is intended to be shown to visitors as the 404 page, it uses the application layout as set up here but you can set :layout to false or whatever other layout you might wish to use.
In the application controller add the following lines:
rescue_from ActiveRecord::RecordNotFound, :with => :missing_page rescue_from ActionController::UnknownAction, :with => :missing_page rescue_from ActionController::RoutingError, :with => :missing_page
The first two lines work as expected, the line with ActionController::RoutingError does not work correctly though, it will start working once the bug is fixed.
The temporary fix for routing errors not being handled properly is to add the following line as the last route in the route file.
match '*path', :to => 'errors#missing_page'
Once the bug is fixed all you need to do to clean this up is remove the line that was placed at the end of the route file.