【问题标题】:rake task error : undefined method 'perform' for main:Objectrake 任务错误:main:Object 的未定义方法“执行”
【发布时间】:2015-02-22 09:10:17
【问题描述】:

谁能建议我哪里出错了?

我尝试执行以下任务,但以

结束
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

【问题讨论】:

    标签: ruby rake


    【解决方案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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-04
      • 1970-01-01
      • 1970-01-01
      • 2011-07-14
      • 1970-01-01
      • 1970-01-01
      • 2012-05-05
      相关资源
      最近更新 更多