内置的rake任务可以正常工作,但是我的新自定义任务在Project / lib / tasks / payments.rb中没有加载:
namespace :payments do
desc "Tally payments at the end of the month"
task :compute => :environment do
BillingPeriod.compute_new_period
end
end
$ rake payments:compute
(in /Users/rob/Code/Apps/skyfarm)
rake aborted!
Don't know how to build task 'payments:compute'
如果我加载文件application.rb,它可以正常工作:
require 'lib/tasks/payments.rb'
...但是它打破了其他东西:
$ rails s
./lib/tasks/payments.rb:1: undefined method `namespace' for main:Object (NoMethodError)
.rake
文件放在名为目录中rakelib
。