我有这个sample_data.rake文件:
namespace :db do
desc "Fill Patients with sample data"
task populate: enviroment do
Patient.create!(name: ["Example", "User"],
email: "example@gmail.com"
password: "foobar"
password_confirmation: "foobar"
age: "26"
doctor_id: "3"
dao: "true"
active: "true")
350.times do |n|
name=Faker::Name.name
email = "example-#{n+1}@gmail.com"
password = "password"
age = (25...45).sample
doctor_id = [2,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22].sample
dao = ["true", "false"].sample
active = "true"
Patient.create!(name: name,
email: email,
password: password,
password_confirmation: password,
age: age,
doctor_id: doctor_id
dao: dao,
active: active)
end
end
end
它放在lib / tasks上,当我运行rake db:populate我收到下一个错误。
rake aborted!
Don't know how to build task 'enviroment'
/home/marcpursals/.rvm/gems/ruby-1.9.3-p448@migtrace/bin/ruby_noexec_wrapper:14:in `eval'
/home/marcpursals/.rvm/gems/ruby-1.9.3-p448@migtrace/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:populate
我仔细检查了其他帖子:(How to build task 'db:populate',Faker "Don't Know How to Build Task?,Rake aborted Uploading images using faker for ruby project。),但他们没有帮助。
有没有人解决过这样的问题?
提前多多感谢。
答案 0 :(得分:5)
enviroment
应为:environment
,作为拼写正确的符号。
task populate: :environment do
# ...
答案 1 :(得分:1)
你错误地拼写了enviroment
!它应该是environment
。