1

我有这个 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

我仔细检查了其他帖子:(如何构建任务'db:populate'Faker“不知道如何构建任务?Rake中止了使用faker为ruby项目上传图像。)他们没有帮助。

有没有人解决过这样的问题?

提前非常感谢。

4

2 回答 2

5

enviroment应该是:environment,作为正确拼写的符号。

task populate: :environment do
  # ...
于 2013-08-10T13:46:53.850 回答
1

enviroment拼错了!应该是environment

于 2013-08-10T13:46:04.430 回答