1

我正在构建一个具有计划模型和用户模型的应用程序。计划模型有_many用户,负责计划细节、价格等。

我想做的是建立一个 rake 任务,允许我在 heroku 中创建 3 个计划。我一直在弄乱代码,但是当我运行时继续出现错误heroku run rake db:populate_plans

Don't know how to build task 'production'

这是为它编写的代码:

namespace :db do
  desc "fill in plans"
  task populate_plans: :production do

    Plan.create!(name: "Professional", max_phone_numbers: "5", max_minutes: "500", price: "49.95" )

    Plan.create!(  name: "Small Business", max_phone_numbers: "10", max_minutes: "1000", price: "99.95" )       

    Plan.create!( name: "Office", max_phone_numbers: "25", max_minutes: "2000", price: "149.95" )        

    end
  end

非常感谢您对此的任何指导!

4

1 回答 1

0

试试这个

namespace :db do
  desc "fill in plans"
  task :populate_plans => :environment do
    Plan.create!(name: "Professional", max_phone_numbers: "5", max_minutes: "500", price: "49.95" )
    Plan.create!(  name: "Small Business", max_phone_numbers: "10", max_minutes: "1000", price: "99.95" )       
    Plan.create!( name: "Office", max_phone_numbers: "25", max_minutes: "2000", price: "149.95" )        
  end
end

现在运行 rake db:populate_plans RAILS_ENV=production

于 2012-10-08T04:38:33.787 回答