Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Is there an update or update_attributes that throws exception on failure?

Is there an equivalent of model.update or model.update_attributes that throws an exception on failure?

Seems there's not an update! or update_attributes!

like image 769
Catfish Avatar asked Jan 09 '14 18:01

Catfish


Video Answer


1 Answers

I'm not sure why you think there is no update_attributes! because there is. If you were reading the apidock you might have come across an issue such as they talked about here: Why is ActiveRecord::Base#update_attributes deprecated?

Here are the docs detailing the method you want: http://apidock.com/rails/v3.2.13/ActiveRecord/Persistence/update_attributes%21

But, yes, there is an update_attributes! that will raise an exception on validation failure. It calls save! under the hood.

like image 118
DiegoSalazar Avatar answered Oct 07 '22 17:10

DiegoSalazar