Rails ActiveRecord save vs. save!

Posted on October 09, 2007

The subtle difference between these two eluded me for a while, so for those who are just getting started in Rails this tip may be helpful.

If you want to ensure that no ActiveRecord validation errors, etc. were generated when saving a model, do a:
foo.save!
If you do the following instead:
foo.save

The method will return false but an exception will not be generated. I’ve debugged several hair-pulling issues that could’ve been avoided by calling “save!” .