Chamnap
2007-Jun-12 07:46 UTC
How to handle all errors programmatically on saving, updating and deleting records
Hello guys, I want to know how to handle all errors programmatically when I save, update, and delete on record. For the save method, it will return true or false, but for update method and destroy/delete method they seems not to return any valid information they work successfully or not. Appreciate all your idea.... Thanks Chamnap --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
August Lilleaas
2007-Jun-12 08:07 UTC
Re: How to handle all errors programmatically on saving, updating and deleting records
Destroy doesn''t return true or false afaik, it just instantiates the objects and destroys them, calling all the callbacks. Update does a find on the id you pass to it, and saves it. If the save fails, the unsaved object is returned, so I guess you can check wether or not the object changed if you want to figure out if the update was a success or not. On Jun 12, 9:46 am, Chamnap <chamnapchh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello guys, > > I want to know how to handle all errors programmatically when I save, > update, and delete on record. For the save method, it will return true > or false, but for update method and destroy/delete method they seems > not to return any valid information they work successfully or not. > Appreciate all your idea.... > > Thanks > Chamnap--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chamnap
2007-Jun-12 08:14 UTC
Re: How to handle all errors programmatically on saving, updating and deleting records
So it means there is no way that I handle programmatically? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
August Lilleaas
2007-Jun-13 08:11 UTC
Re: How to handle all errors programmatically on saving, updating and deleting records
Of course there is. For update, for instance, the unsaved object is returned, so you can probably do "if myoldobject.eql? mynewobject" for instance. And for destroy - if it didn''t raise anything, it worked. On Jun 12, 10:14 am, Chamnap <chamnapchh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So it means there is no way that I handle programmatically?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chamnap
2007-Jun-13 08:37 UTC
Re: How to handle all errors programmatically on saving, updating and deleting records
What is about if I just handle all exception to make these 3 methods like: begin User.update(12, :email => "kkk-/E1597aS9LQAvxtiuMwx3w@public.gmane.org") # or delete, create true rescue false end What do you think? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
August Lilleaas
2007-Jun-14 08:42 UTC
Re: How to handle all errors programmatically on saving, updating and deleting records
Should work, and looks good. Try it =) On Jun 13, 10:37 am, Chamnap <chamnapchh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What is about if I just handle all exception to make these 3 methods > like: > > begin > User.update(12, :email => "k...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org") # or delete, create > true > rescue > false > end > > What do you think?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---