简体   繁体   中英

Rake Tasks ERROR : Don't know how to build tasks 'production'

I'm building an app which has a plan model, and a users model. The plan model has_many users, and is responsible for plan details, price etc.

What I'd like to do, is to build a rake tasks which allows me to create 3 plans in heroku. I've been messing around with the code, but keep on getting the error, when I run heroku run rake db:populate_plans

Don't know how to build task 'production'

Here's the code written for it :

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

Any guidance on this is greatly appreciated!

try this

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

now run rake db:populate_plans RAILS_ENV=production

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM