Rubytastic
Rubytastic

Reputation: 15501

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'

Upvotes: 54

Views: 56678

Answers (5)

David Hempy
David Hempy

Reputation: 6287

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.

Upvotes: 13

super1ha1
super1ha1

Reputation: 629

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

As is: deploy_app  (not work)
To be: deployapp   (working)

Upvotes: 2

Morgan
Morgan

Reputation: 37

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.

Upvotes: 2

esc_rtn
esc_rtn

Reputation: 936

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

Upvotes: 16

cjc343
cjc343

Reputation: 3765

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

Related: How to build task 'db:populate'

Upvotes: 107

Related Questions