Say I wish to create a user from console with an email which already exists. If I do User.create(...)
Because of model validations (uniqueness in this case). create
fails and the output in rails console will say: rollback transaction
(user is not saved)
For the purpose of testing. Is their a way I can get the explicit error which triggered the rollback? In this case it would say something like: "ROLLBACK: email is not unique".
You can also do:
User.create!
The 'bang' will force it to show you the errors without additional steps.
You could do the following in Rails console:
>> user = User.new(...)
>> user.save
>> user.errors.messages
That way, you know what errors caused save
to fail.
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