Render 404 Error instead of 500 on ::ActionController::Routi

I want to render a 404 whenever ActionController::RoutingError is
thrown in my application. This works in my apps running the 1.1.6 gem,
but not when running on edge rails or 1.2-RC1. I suspect it has
something to do with this (from the RoR blog):

“Uncaught exceptions raised anywhere in your application will cause
RAILS_ROOT/public/500.html to be read and shown instead of just the
static “Application error (Rails).” So make it look nice if you
aren’t using it already!”
(http://weblog.rubyonrails.org/2006/11/26/1-2-new-in-actionpack)

Anybody have any ideas how to override this for Routing Errors?

Did you ever figure this out? I want the same thing…404’s instead
of 500’s for routing errors.

Thanks.

patrick

On 11/28/06, tharealpatton [email protected] wrote:

(http://weblog.rubyonrails.org/2006/11/26/1-2-new-in-actionpack)

Anybody have any ideas how to override this for Routing Errors?


http://www.xblabs.com

Wouldn’t you just use this method in your application controller?

def rescue_action_in_public(exception)
case exception
when RoutingError, UnknownAction, ActiveRecord::RecordNotFound
then
render :controller => “application”, :action => “error_404”,
:status => 404
else
render :file => “errors/unhandled”, :status => 505
end
end

Also, here’s a blog talking about doing the same thing.
http://www.sitepoint.com/blogs/2006/08/30/being-a-good-little-404er/

Jason

My bad, apparently rescue_action_in_public doesn’t catch
ActionController::RoutingError. It does catch UnknownAction and
RecordNotFound…this is interesting and I hope I can figure out how to
fix it.

Jason N. wrote:

My bad, apparently rescue_action_in_public doesn’t catch
ActionController::RoutingError. It does catch UnknownAction and
RecordNotFound…this is interesting and I hope I can figure out how to
fix it.

Yeah, that’s what I’ve been trying to figure out…

Any insight into this would be awesome.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs