I think this should work, I have a Transactions model, and I’m trying to create a new record…
transaction = Transaction.new do |t|
t.user_id = cart.user_id
t.postal_carrier = 'Canada Post'
t.invoice_number = ''
t.transaction_msg = "shipment pending..."
It’s not saving anything.
oh, i forgot i have some validations it did not pass.
Yep, when validations don’t pass,
record.save will return false. (So will
record.valid?) One can then inspect the errors using
One small piece of advice, I wouldn’t name a model
Transaction for the risk of confusion with an Activerecord Transaction. The alternative would be to qualify your business-land Transaction using some kind of prefix or module. (eg.
OurCompany::Transaction, or some similar workaround).