I'm unable to create a row in the DB. Rails apparently starts and then immediately rolls back the transaction without any errors. I'm using sqlite3.
logger.debug("creating billing name...")
BillingName.create() #also tried BillingName.new.save
logger.debug("...created")
Log file:
creating billing name...
^[[1m^[[36m (0.1ms)^[[0m ^[[1mbegin transaction^[[0m
^[[1m^[[35m (0.1ms)^[[0m rollback transaction
...created
select * from billing_name
shows indeed no entry has been added. How can I tell why the transaction is being rejected?
You can check the errors after a save
or valid?
billing_name = BillingName.new
billing_name.save # or billing_name.valid?
puts billing_name.errors.inspect
These are good answers that help you find the error by inspecting the model. I use those too.
But I've found that ActiveRecord doesn't always provide useful information, especially in callbacks. valid?
will be true, errors will be empty, and the console won't show anything except the rollback. So, a good place to look is what is happening in those callbacks, specifically the before_create filter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With