我正在编写一个rake任务,以更新表中特定列中的值。当我运行任务时,我会得到以下错误:
uninitialized constant FirstLookSubscription以下是rake任务代码:
namespace :first_look_db do
desc "Adds one month to the Look Subscription"
FirstSubscription.where(subscription_state: 'active').each do |t|
t.update_attribute :next_billing_check, '2013-9-10'
end
end我刚开始收集任务,我不想把它作为迁移来完成。任何建议都会很棒的!
还请注意:当我在rails控制台中运行它时,它执行时没有问题,我最大的问题是将它转换为rake任务,这样我们的铅dev就可以运行它了。
发布于 2013-07-24 00:25:55
你真的需要一个任务名称。namespace给出任务的命名空间,但根据名称声明任务并导入环境,以便找到您的ActiveRecords:
namespace :first_look_db do
desc "Adds one month to the Look Subscription"
task :add_month_to_look_sub => :environment do
FirstSubscription.where(subscription_state: 'active').each do |t|
t.update_attribute :next_billing_check, '2013-9-10'
end
end
end这将进入一个名为lib/tasks/first_look_db.rake的文件。该任务由以下人员调用:
rake first_look_db:add_month_to_look_sub或可能:
bundle exec rake first_look_db:add_month_to_look_sub如果第一个让你这么做的话。您可以将namespace和task命名为rake文件中的任意名称。我只是从你的名字中挑出了一些对我来说有意义的名字。
https://stackoverflow.com/questions/17823005
复制相似问题