Hello,
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,
::ActionController::UnknownAction,
::ActionController::RoutingError
render(:file => "#{RAILS_ROOT}/public/404.html",
:layout => 'application',
:status => "404 Not Found")
#SystemNotifier.deliver_exception_notification(
# self, request, exception)
else
render(:file => "#{RAILS_ROOT}/public/500.html",
:layout => 'application',
:status => "500 Error")
#SystemNotifier.deliver_exception_notification(
# self, request, exception)
end
end
But, it only works at the root level. If you go to
http://www.pawsitiveapproach.ca/foobar, then you get the main layout on
the 404 page. But, if you go to
http://www.pawsitiveapproach.ca/articles/foobar, 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 =>
‘admin_petfact’
map.connect ‘/admin/testimonials/:action/:id’, :controller =>
‘admin_testimonial’
map.connect ‘/admin/articles/:action/:id’, :controller =>
‘admin_article’
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’
end
Also, how do you catch routing errors? I’m trying to in my exception
handler above, but it’s not working.
Thanks,
Mike