Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple rails rake task refuse to run with error "Don't know how to build task", why?

I have this simple rake task which refuses to run. I just don't see why it looks correct. Who can pinpoint me to the probably very simple mistake I made? Thank you!

/lib/tasks/reindex.rb:

namespace :db do

  desc "Tire reindex profiles"

  task :reindex => :environment do
    system "cd #{Rails.root} && rake environment tire:import CLASS='Profile' FORCE=true"
  end

end

The error:

rake db:reindex
rake aborted!
Don't know how to build task 'db:reindex'
like image 271
Rubytastic Avatar asked Oct 15 '12 19:10

Rubytastic


5 Answers

Rename your file to reindex.rake and it should work.

Related: How to build task 'db:populate'

like image 70
cjc343 Avatar answered Oct 23 '22 12:10

cjc343


You can also get this error if you forget to put the namespace before your task name. (i.e. :reindex instead of db:reindex)

like image 35
esc_rtn Avatar answered Oct 23 '22 13:10

esc_rtn


The file extension for rake tasks must be '.rake'.

If you named your file as '.rb', then rake will not find it, and you will question your own sanity for several minutes before ending up here.

like image 39
David Hempy Avatar answered Oct 23 '22 12:10

David Hempy


Don't forget to check that you call the name of the task and not the file name. The best thing is that they be named the same.

like image 2
Morgan Avatar answered Oct 23 '22 12:10

Morgan


This error happen to me is because the namespace name got underscore

As is: deploy_app  (not work)
To be: deployapp   (working)
like image 2
super1ha1 Avatar answered Oct 23 '22 12:10

super1ha1