I'm trying to preload all devise accounts in advance using rake db:seed. Data for all other models seems to be inserted in the database but for some reason NO rows are created for Person model which uses devise. Registration from web interface works fine, but I want to avoid creating accounts manually, thats the reason i'm using rake db:seed. I copied encrypted_password,password_salt from an account created via web interface. Please let me know how to get around this? Many thanks..
people = Person.create( :email => 'firstname.lastname@example.org', :encrypted_password => '$2a$10$SyacAOhJQtVeTcTPYm.ROuFbhGMylfj4fLrK3NHyeRwfEokKp2NVW', :password_salt => '$2a$10$SyacAOhJQtVeTcTPYm.ROu', :first_name => "nnn", :last_name => "yyy" ) in routes.rb i have. devise_for :people
preguntado el 08 de enero de 11 a las 16:01
I've done this using Devise in the past. I didn't try setting the encrypted password and salt that way. I just set the password and confirmation something like this (I dont have my project handy):
Person.create(:email => 'email@example.com', :password => 'foobar', :password_confirmation => 'foobar', :first_name => 'nn', :last_name => 'yy')
Most likely the "create" method fails quietly due to model validation and therefore returns false. You would've seed the errors if you used "create!" method instead (with exclamation) - this method raises the exception if validation fails.
The likely reason for validation failure in your case is that (by default for Devise) minimum password length is 6 characters and you were not supplying password at all.
If you don't want duplicates while running rake db:seed multiple times:
User.create( email: email, password: password, password_confirmation: password ) unless User.where(email: email).exists?