2016-05-13 75 views
0

我想與初始用戶種子數據庫。前兩個測試帳戶和精細填充:耙分貝:種子不按預期工作

User.create! :name => "Name", :surname => "Lastname", :admin => 't', :email => "[email protected]", :encrypted_password => "Password"

User.create! :name => "name", :surname => "lastname", :admin => 'f', :email => "[email protected]", :encrypted_password => "Password"

然而,當我嘗試運行觸發錯誤NameError: undefined local variable or method 'name' for main:Object

8.times do 
User.create! :name => Faker::Name.first_name, :surname => Faker::Name.last_name, :admin => 'f', :email => Faker::Internet.email(name + "." + surname), :encrypted_password => Faker::Internet.password(10) 
end 

我想不出問題。任何幫助?謝謝。

回答

0

結束了與此:

8.times do 
name = Faker::Name.first_name 
surname = Faker::Name.last_name 
encrypted_password = Faker::Internet.password(10) 
user_list << [name, surname, 'f', Faker::Internet.email(name + "." + surname), encrypted_password] 
end 
user_list.each do |name, surname, admin, email, encrypted_password| 
    User.create!(name:name, surname:surname, admin:admin, email:email, encrypted_password:encrypted_password) 
end