Basic Rails 404 Error Page

in your ApplicationController

unless  ActionController::Base.consider_all_requests_local
  rescue_from Exception, :with => :render_404
end

private

  def render_404
    render :template => 'error_pages/404', :layout => false, :status => :not_found
  end

now set up error_pages/404.html and there you go

...or maybe I'm overcautious with Exception and you should rescue from RuntimeError instead.


I believe that if you run in production mode, then 404.html in the public directory gets served whenever there are no routes for a URL.


If you run in production mode, 404.html,500.html,422.html files in public directory gets served whenever there respective error occured, pages from above will be shown.

In rails 3.1

We can use like below: Rails 3.1 will automatically generate a response with the correct HTTP status code (in most cases, this is 200 OK). You can use the :status option to change this:

render :status => 500

render :status => :forbidden

Rails understands both numeric and symbolic status codes.

Fore more information see this page

Cheers!