我正在构建一个具有计划模型和用户模型的应用程序。计划模型有很多用户,负责计划细节,价格等。
我想做的是建立一个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
非常感谢任何关于此的指导!
答案 0 :(得分: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