How to handle all errors programmatically on saving, updatin

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

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.

So it means there is no way that I handle programmatically?

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.

Should work, and looks good. Try it =)

What is about if I just handle all exception to make these 3 methods
like:

begin
User.update(12, :email => “[email protected]”) # or delete, create
true
rescue
false
end

What do you think?