Rails does this for you automatically when you start in production mode. When you download the application to a live server, Rails takes care of handling these exceptions and displays the correct error pages with the correct header status. If you are trying to see what these pages look like (for testing or something else), just access them directly through http://localhost:3000/404.html
Whenever you configure a Rails application on a real server (let it use Apache as an example), you provide the site root as the /public folder in your application. Then, whenever a request is made to the address of this server, Apache first looks at this shared folder and tries to service the static asset (this is a custom parameter in [environment].rb ). If it cannot find the requested page, the request is sent through the Ruby stack.
In production mode, if Rails detects an error that is not being processed (for example, start, save), it gives an error all the way to the stack, which then tells Apache (again, in my example) to make the corresponding error.
Here are some common errors that you will see in development mode and what they display in production mode:
ActiveRecord::RecordNotFound => 404 (page not found) nil.method => 500 (server error) unless you turn off whiny nils ActionController::RoutingError => 404 (page not found)
sethvargo
source share