2012-10-08 113 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) –

相關問題