A memo about dealing with rollback transaction errors in Devise model for Ruby on Rails 5.
This kind of error occurs:
irb(main):006:0> User.create(username: 'yuis')
(0.0ms) begin transaction
(0.0ms) rollback transaction
=> #<User id: nil, email: "", created_at: nil, updated_at: nil, provider: nil, uid: nil, username: "yuis", disc: nil>
Cause: Devise internally requires email addresses and passwords, and throws errors if they are missing, but those errors are only for the Controller, so errors are not output. You might notice if you have double validation/constraints in the database, but if not, it’s hard to notice.
Solution: Properly enter email address and password too
irb(main):005:0> User.create(username: 'yuis' , email: '[email protected]' , password: "hogehoge" )
...
=> #<User id: 9, email: "[email protected]", created_at: "2018-07-06 20:51:19", updated_at: "2018-07-06 20:51:19", provider: nil, uid: nil, username: "yuis", disc: nil>
It seems there’s also a possibility that the email address validation regex pattern is wrong, but I think this possibility is actually more likely.