Basic Rails 404 Error Page

Viewed 24427

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.

6 Answers

Here's how I do it. In my application_controller.rb:

def render_404
  render file: 'public/404.html', layout: false, status: :not_found
end

Then, in any controller where I want to render a 404, I do something like this:

@appointment = Appointment.find_by(id: params[:appointment_id]) || render_404
Related