02 Nov 2012
If you use "save" on an invalid record, it will not be saved:
post = Posts.new do |p| p.title = "example" p.body = "An example" end post.save
This code may work at the moment, but it is fragile. If a later refactoring introduces a new required column to Posts, then the
save call will silently start failing.
If you think the record can never be invalid, or don't want to check the return value, use "save!"
post = Posts.new do |p| p.title = "example" p.body = "An example" end post.save!
Now you will get an error if the
post cannot be saved, which will alert you to the problem.