# How to render my own error pages correctly?

**URL:** <https://www.ruby-forum.com/t/how-to-render-my-own-error-pages-correctly/91479>\
**Category:** Rails\
**Created:** [April 9, 2007, 5:46pm UTC](https://www.ruby-forum.com/t/how-to-render-my-own-error-pages-correctly/91479 "2007-04-09T17:46:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@rob](https://www.ruby-forum.com/u/rob)\
**Post date:** [April 9, 2007, 5:46pm UTC](https://www.ruby-forum.com/t/how-to-render-my-own-error-pages-correctly/91479/1 "2007-04-09T17:46:16Z")

</div>

Hi there,

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

I raise an error in my controller:  
raise MyException.new, “Bad thing.”

Therefore I defined:  
class MyException \< Exception  
end

Furthermore I catch that in application.rb:  
def rescue\_action\_in\_public(exception)  
case exception  
when MyException  
logger.error(“404 displayed”)  
render :file =\>  
“#{RAILS\_ROOT}/public/errorpages/404\_myerror.html”,  
: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 =\>  
false”!

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 😉

Thanks,  
Rob
