Forum: Ruby on Rails How do you detect if 'update' save fails?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ba8407b72aa8011fd47fa2fcec5ec6d2?d=identicon&s=25 Justin Rhoades (Guest)
on 2005-12-27 07:34
(Received via mailing list)
So I'm updating multiple model objects in one go with something like
this in my controller:
=>	Photo.update(params[:photo].keys, params[:photo].values)

When the update fails due to validation errors, how do I detect it?
The Rails API says:
"If the save fails under validations, the unsaved object is still
returned."
So I can't simply do this:
  =>	if Photo.update(params[:photo].keys, params[:photo].values)

Any suggestions?
B4a3fe24e9fb82df573ae5b38aa3b872?d=identicon&s=25 Derek Chesterfield (Guest)
on 2005-12-27 14:32
(Received via mailing list)
photo=Photo.find params[:id]
unless photo.update_attributes params
   #error handling
end
This topic is locked and can not be replied to.