Forum: Ruby on Rails Missing Template Should be 404 Error

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Aaron Longwell (Guest)
on 2007-01-24 11:08
(Received via mailing list)
I have a site I'm building that has the template dynamically chosen
upon some parameters of the request. There are cases where a nonexistent
template will be sent to the render method. For purposes of my
this is not a serious, fatal error, but a simple HTTP 404 error code.
Unfortunately, Rails disagrees, and it's sending a 500 error message in

How can I override this behavior?

What is the justification for template missing to be treated as a 500
instead of 404 error?
Matias S. (Guest)
on 2007-01-24 11:18
(Received via mailing list)

Aaron Longwell
> I have a site I'm building that has the template dynamically chosen based
Aaron Longwell (Guest)
on 2007-01-24 19:03
(Received via mailing list)
That site is similar to a lot of other stuff I've seen. It appears that
catching missing method errors is a much more common problem than
missing *template* errors.

I can't use method_missing, because my error happens after the call to
render (after the correct action method has begun executing)... and I
believe template_missing exists... but I have found a (the?) solution.

As it turns out, rescue_action_in_public can catch the MissingTemplate
error, but I was not detecting the error properly in my previous
attempts. I
was failing to use global scope when specifying Missing Template. Here's
what works:

if exception.kind_of? ::ActionController::MissingTemplate
  render :status => 404, :text => (,
'public', '

That code is effectively converting 500 errors from MissingTemplate into
errors just like other rails features. Excellent.

Notice the "::" before ActionController. Failing to include that results
the exception handler throwing an error of its own.. which I didn't
This topic is locked and can not be replied to.