我有这个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:popul时,我会得到下一个错误。
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
我仔细检查了其他帖子:(如何构建任务';db:popul';,Faker';不知道如何构建任务?,Rake中止了使用Faker为ruby项目上传图像。)但它们没有帮助。
有人解决了这样的问题吗?
提前非常感谢。
enviroment
应该是:environment
,作为拼写正确的Symbol。
task populate: :environment do
# ...
您拼错了enviroment
!它应该是environment
。