ironsand
ironsand

Reputation: 15181

Rake doesn't find '*.rake' file in 'lib/tasks' directory

I have a foo.rake file in lib/tasks directory of a Rails project.

namespace :foo do
  desc 'rake task example'
  def bar
    p "foo bar"
  end
end

But the rake command can't find the task, the following command outputs nothing.

bundle exec rake -T -A | grep foo

How can I run a rake task from command line?

Upvotes: 2

Views: 757

Answers (2)

jjg
jjg

Reputation: 1024

Add the line

Rake.add_rakelib('lib/tasks')

to your Rakefile.

Upvotes: 0

Tamer Shlash
Tamer Shlash

Reputation: 9523

Rake tasks are defined like so:

namespace :foo do
  desc 'rake task example'
  task :bar do
    # Your code here
  end
end

Notice task :bar do instead of a usual method definition style def bar.

Upvotes: 3

Related Questions