Forum: Ruby on Rails How to render my own error pages correctly?

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.
076a7adf60418c9219df951132fea8df?d=identicon&s=25 Rob (Guest)
on 2007-04-09 17:46
Hi there,

I am trying to get my own error pages (404 for example) displayed

I raise an error in my controller:
raise, "Bad thing."

Therefore I defined:
class MyException < Exception

Furthermore I catch that in application.rb:
  def rescue_action_in_public(exception)
    case exception
      when MyException
         logger.error("404 displayed")
          render :file =>
                     :status => "404", :layout => false

So far, so good. I get my page displayed. BUT everytime my application
layout (application.rhtml) gets rendered too! Look, I've set ":layout =>

The problem is, that I can not get a really 404 error with this. I alws
get 200 error. I think it is beacause the 404_myerror.html is rendered
within this application.rhtml. I can verify this via console:

>> app.get "/produceerror/bad"
=> 200

(in my action "bad" i raise the 404)

What do you think? This Exception handling for errors is a bit sucky ;-)

This topic is locked and can not be replied to.