Rails 4.1. Develop 3.3. Users.password does not exist.

I want to create a user manually through the console as such:

User.find_or_create_by(email: "user@mail.com", 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 does not work. It does not match the attribute of the Devise password model, 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. Has something changed in recent versions?

Thank.

+4
source share
2 answers

Instead User.find_or_create_byyou should use User.create.

Devise accepts a password confirmation and password upon creation, but there is a column with a name in the actual table encrypted_password.

"find" User.find_or_create_by "", .

+8

, find_or_create_by, :

User.find_or_create_by(email: "user@mail.com", first_name: "Stan", last_name: "Smith") do |user|
  user.password = "password"
  user.confirmed_at = Time.now
end
+4

All Articles