有谁能建议我哪里出错了?
我尝试执行以下任务,但最终以
结束rake aborted!
NoMethodError: undefined method 'perform' for main:Object
这是我的佣金任务
task :update_state_for_search_request => :environment do
t_last = MyModule.where("condition").last.id
t_first = 0
until t_first >= t_last do
t_first=print_id(t_first)
end
def perform(sid)
# action
my_data = MyModule.where("name='abcd' and id > #{sid}").limit(1000)
# action
return my_data.last.id
end
end
答案 0 :(得分:1)
您正在rake任务中定义方法,这是此处的问题。在任务之外定义它。
task :update_state_for_search_request => :environment do
t_last = MyModule.where("condition").last.id
t_first = 0
until t_first >= t_last do
t_first=print_id(t_first)
end
end
def perform(sid)
# action
my_data = MyModule.where("name='abcd' and id > #{sid}").limit(1000)
# action
return my_data.last.id
end
另请参阅此SO:def block in rake task