Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic Rails 404 Error Page

Tags:

I have been looking for a simple answer to this for a ridiculously long time and it seems like this has to be so plainly obvious and simple because no one has an easy, idiot proof tutorial.

Anyway, all I want to do is to have a single 404.html static page that loads whenever ANY error is thrown. Ideally this should only happen in production and staging.

I feel like this should be the easiest thing to do... but I can't figure it out.

Any help is much appreciated.

like image 436
chrishomer Avatar asked Sep 19 '09 03:09

chrishomer


1 Answers

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.

like image 59
Leonid Shevtsov Avatar answered Sep 25 '22 13:09

Leonid Shevtsov