bigbanger
2008-Jan-27 01:32 UTC
Rails 2.0 error ActiveRecord handling/reporting best practice.
I''ve included rescue_from ActiveRecord::RecordNotFound in my application.rb file in order to catch and report all failed ActiveRecord find operations. However, ActiveRecord does not raise this exception from the dynamic finders that it includes in models. So is the best practice to avoid use of the dynamic finders and only use find() instead? Or is it common to make use of the dynamic finders and have my controller raise ActiveRecord::RecordNotFound when a dynamic finder returns nil? Just curious how others typically handle this sort of thing. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jean-Sébastien
2008-Jan-27 02:01 UTC
Re: Rails 2.0 error ActiveRecord handling/reporting best practice.
you can do it to thrown an exception: self.find_by_id(id) || ActiveRecord::RecordNotFound and you can also read this discution which is really interesting about the topic : http://groups.google.com/group/rubyonrails-core/browse_thread/thread/9b79f15be8cea7ab/465c7b2f24b03363 On Jan 27, 2:32 am, bigbanger <bigbanger...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve included > > rescue_from ActiveRecord::RecordNotFound > > in my application.rb file in order to catch and report all failed > ActiveRecord find operations. However, ActiveRecord does not raise > this exception from the dynamic finders that it includes in models. > So is the best practice to avoid use of the dynamic finders and only > use find() instead? Or is it common to make use of the dynamic > finders and have my controller raise ActiveRecord::RecordNotFound when > a dynamic finder returns nil? Just curious how others typically > handle this sort of thing.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---