最佳答案
内置的 rake 任务工作得很好,但是我的新自定义任务 Project/lib/asks/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)