Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create Devise account using rake db:seed for Rails 3.0

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 => '[email protected]',
                        :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
like image 693
amj Avatar asked Jan 08 '11 16:01

amj


2 Answers

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 protected]', :password => 'foobar', :password_confirmation => 'foobar', :first_name => 'nn', :last_name => 'yy')

Try that.

like image 188
ffoeg Avatar answered Oct 31 '22 17:10

ffoeg


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.

like image 44
Alex Kovshovik Avatar answered Oct 31 '22 17:10

Alex Kovshovik