4

I'm used to enhance rake tasks, but today rake do not want to collaborate...

In particular I want to enhance rake tmp:clear. And as usual I tried this way:

Rake::Task["tmp:clear"].enhance do 
    puts "enhanced"
end

I always get a Don't know how to build task 'rake tmp:clear' on execution.

I tried to:

  • Rename my xxx.rake file that contain this piece of code.
  • Remove everything but this piece of code.
  • Look into rake tasks/tmp.rake source code to see if tmp:clear had some other weird treatment.
  • And of course Googled a lot...

I ended up with no solutions/clues.

Thanks for any help. Flavien

Footnotes:

  • It works if I change "tmp:clear" for "assets:clobber" for exemple. But still not for "tmp:cache:clear" or other related to tmp.
  • I use rails 4.2
Flavien
  • 95
  • 9

1 Answers1

4

This is a problem I was facing as well and I was finally able to trace down what was happening. It seems that rails is not including the tmp tasks until after the local rake tasks were loaded. This does not apply to assets:clobber however since those are not declared in the same location as the tmp rake tasks. You can see more information about the declarations. I was able to fix this by adding

require 'rails/tasks'

to the top of my tmp.rake file in tasks, so in your case it would look like

require 'rails/tasks'

Rake::Task["tmp:clear"].enhance do 
    puts "enhanced"
end

and then everything worked for me as expected.

theother404
  • 193
  • 1
  • 11