When do I use save!, create! and update_attributes! in Rails?

The main difference is how failed saves are handled. When updating an ActiveRecord class the ! version will raise an exception if the record is invalid.

I recommend reading the docs here – http://api.rubyonrails.org/classes/ActiveRecord/Base.html

Using transactions might also be something worth looking into – http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)