1. Create an ErrorsController in app/controllers
def not_found
respond_to do |format|
format.html { render template: “errors/not_found”,
layout: “layouts/application”,
status: 404 }
end
end
def server_error
respond_to do |format|
format.html { render template: “errors/server_error”,
layout: “layouts/application”,
status: 500 }
end
end
end
2. Add these to your routes.rb file
match “/500”, :to => “errors#internal_server_error”, :via => :all
3. Add this to your application.rb file
4. Delete public/404.html, public/422.html, and public/500.html
5. Remember while developing you should change this to false in config/environments/development.rb
If you fail to perform this step, Rails will show you full stacktraces instead of your error page.
Sample app can be found here