rendering a 404 page with a layout


I want my 404 and 500 pages to use the application layout, so they look
like the rest of my site. So, I'm doing this

    def rescue_action_in_public(exception)
        logger.error("rescue_action_in_public executed")
        case exception
        when ActiveRecord::RecordNotFound,
            render(:file => "#{RAILS_ROOT}/public/404.html",
                   :layout => 'application',
                   :status => "404 Not Found")
            # self, request, exception)
            render(:file => "#{RAILS_ROOT}/public/500.html",
                   :layout => 'application',
                   :status => "500 Error")
            # self, request, exception)

But, it only works at the root level. If you go to, then you get the main layout on
the 404 page. But, if you go to, you don't.

Is this just a routing issue? Here are my routes.

ActionController::Routing::Routes.draw do |map|
  # With no path provided, default to the front page.
  map.connect '', :controller => "main", :action => 'index'

  # Route for the admin section.
  map.connect '/admin/petfacts/:action/:id', :controller =>
  map.connect '/admin/testimonials/:action/:id', :controller =>
  map.connect '/admin/articles/:action/:id', :controller =>
  map.connect '/admin/users/:action/:id', :controller => 'admin_users'

  map.connect '/admin/', :controller => 'admin', :action => 'index'

  # Map for the top-level, so we don't see 'main' in the URLs.
  map.connect '/:action/:id',
    :controller => "main", :requirements => { :id => /^\d+$/ }

  # Standard route.
  map.connect ':controller/:action/:id'

Also, how do you catch routing errors? I'm trying to in my exception
handler above, but it's not working.


what version of Rails are you using? I'm running edge rails right now
(changeset 5533) and having a similar problem.

I was doing the same thing msoulier is doing above by trying to catch
RecordNotFound and RoutingErrors with rescue_action_in_public but it
seems to be broken in Edge Rails. It worked fine in 1.1.6.