2012-10-08 41 views
1

我建立具有计划模型的应用和用户模式。该计划模型的has_many用户,并负责计划的细节,价格等Rake任务错误:不知道如何建设任务“生产”

我今天准备这样做,是要建立一个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

你的任务被命名为'分贝:populate_plans' ... –

+0

...哇,这是愚蠢的我。改为Heroku的运行耙分贝:populate_plans,但现在我得到的错误:不知道如何运行任务“生产”。思考? –

+1

1.为什么不使用种子? 2.您是否尝试将':production'更改为':environment'? –

回答

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 

现在运行耙分贝:populate_plans RAILS_ENV =生产

+0

A和该诀窍!有一个问题 - 似乎名称,max_phone_numbers和max_minutes等没有注册。该计划已创建,但其值为零。你为什么会这样想? –

+0

尝试在控制台创建计划,检查它发生了什么。 也试试这个 - Plan.create(:名称=> “专业”,:max_phone_number => 5:max_minutes => 500:价格=> 49.95) –

相关问题