tharealpatton
2006-Nov-29 03:01 UTC
Render 404 Error instead of 500 on ::ActionController::RoutingError
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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Patrick Crosby
2007-Jan-12 14:30 UTC
Re: Render 404 Error instead of 500 on ::ActionController::RoutingError
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 <pj-KuE4Goz3TDoncWgORnbzmV6hYfS7NtTn@public.gmane.org> wrote:> > 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? > > > > >-- http://www.xblabs.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jason Norris
2007-Jan-12 14:47 UTC
Re: Render 404 Error instead of 500 on ::ActionController::RoutingError
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
Patrick Crosby wrote:> 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
<pj-KuE4Goz3TDoncWgORnbzmV6hYfS7NtTn@public.gmane.org> wrote:
>
>> 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?
>>
>>
>>
>
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Jason Norris
2007-Jan-12 18:26 UTC
Re: Render 404 Error instead of 500 on ::ActionController::RoutingError
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.> 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 > > Patrick Crosby wrote: > >> 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 <pj-KuE4Goz3TDoncWgORnbzmV6hYfS7NtTn@public.gmane.org> wrote: >> >> >>> 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? >>> >>> >>> >>> >> >> > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
tharealpatton
2007-Jan-12 19:11 UTC
Re: Render 404 Error instead of 500 on ::ActionController::RoutingError
Jason Norris 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---