rake db:种子没有按预期工作

时间:2016-05-13 01:42:21

标签: ruby-on-rails-3 seeding faker

我正在尝试为初始用户播种数据库。前两个是测试帐户并填写正常:

User.create! :name => "Name", :surname => "Lastname", :admin => 't', :email => "admin@testing.co", :encrypted_password => "Password"

User.create! :name => "name", :surname => "lastname", :admin => 'f', :email => "test@faker.tld", :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

我无法弄清楚问题所在。有帮助吗?感谢。

1 个答案:

答案 0 :(得分: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