I want to create a user manually through the console as such:
User.find_or_create_by(email: "[email protected]", first_name: "Stan", last_name: "Smith", password: "password", password_confirmation: "password", confirmed_at: Time.now)
I have done this many times in past projects but this time it's not working. It is not picking up the Devise password model attribute so this is the error I get:
PG::UndefinedColumn: ERROR: column users.password does not exist
I have Rails 4.1.4 and Devise 3.3.0. Did something change in the latest versions?
Thanks.
Instead of User.find_or_create_by
you should be using User.create
.
Devise accepts a password and password confirmation on creation but the actual table only has a column called encrypted_password
.
The "find" portion of User.find_or_create_by
is looking for a column called "password" which doesn't exist.
Still if you want to use find_or_create_by
, it accepts block:
User.find_or_create_by(email: "[email protected]", first_name: "Stan", last_name: "Smith") do |user|
user.password = "password"
user.confirmed_at = Time.now
end
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