Search code examples
ruby-on-railsspree

What is the exclamation mark in Spree::Product.create(exclamation mark) method?


I ran into some problems with Spree and saw this code, which mentions Spree::Product.create! (rather than Spree::Product.create without !)

I would like to understand the differences between the 2 methods.


Solution

  • The bang versions (e.g. Spree::Product.create!) raise an exception if the record is invalid. The non-bang versions don’t: Spree::Product.create return false.

    Ref: http://edgeguides.rubyonrails.org/active_record_validations.html#when-does-validation-happen-questionmark