How to build task 'db:populate'
Asked Answered
Y

3

10
  1 namespace :db do
  2   desc "Fill database with sample videos"
  3   task :populate => :environment do
  4     require 'faker'
  5     Rake::Task['db:reset'].invoke
  6     100.times do |n|
  7       headline = Faker::Lorem.sentence(3)
  8       video = Faker::Lorem.words(5)
  9       Video.create!(:headline => headline,
 10                   :video => video)
 11     end
 12   end
 13 end

I currently have this rake task in lib/tasks/sample_data.rb

When running rake db:populate I get the error, Don't know how to build task 'db:populate'. How do I get around this?

Notes: I am a newbie in Rails/Ruby. I am using Rails 3.

Yann answered 17/3, 2011 at 3:20 Comment(0)
W
24

Try renaming the file to sample_data.rake.

I was able to get your example working (replacing the internals of the task with a p statement) by putting your code in a file called testomatic.rake in lib/tasks.

Whirligig answered 17/3, 2011 at 4:6 Comment(1)
Just did the same thing myself! It's always the simple things that get me.Bubble
L
3

I also had this problem. In Finder, the file name was sample_data.rake, but upon clicking "Get Info" for the file, I discovered the full file name was sample_data.rake.erb -- ensure that's not your problem.

Lusk answered 13/4, 2011 at 19:14 Comment(0)
L
1

Noobie with the same problem here - my branch was named differently than what I thought when I merged branches, so it reverted back to the old files before I had created my lib/tasks/sample_data.rake file.

Simply going back and re-running git merge with the correct name and pushing to Heroku got it to work.

Letters answered 27/10, 2013 at 21:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.