带有轨道滑槽的未定义方法



我在任何时候都在使用gem,但我无法让我的runner指令正常工作。

我得到这个错误:

/Users/bl0b/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.11/lib/rails/commands/runner.rb:53:in `eval': undefined method `run' for #<Class:0x007f97d88744a8> (NoMethodError)
    from (eval):1:in `<top (required)>'
    from /Users/bl0b/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.11/lib/rails/commands/runner.rb:53:in `eval'
    from /Users/bl0b/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.11/lib/rails/commands/runner.rb:53:in `<top (required)>'
    from /Users/bl0b/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.11/lib/rails/commands.rb:64:in `require'
    from /Users/bl0b/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.11/lib/rails/commands.rb:64:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

我的shedule.rb:中有以下代码

set :environment, 'development' 
     every 1.minutes do
       runner "Crawler.run", :output => '/Users/bl0b/Projects/crawler/cron.log'  
     end

在我的app/models/crawler.rb中,我有以下代码:

class Crawler < ActiveRecord::Base
  def run
    puts "toto"
  end
end

您正试图在Crawler上调用一个类方法,但该方法被定义为实例方法。要使你的方法成为类方法,你可以这样定义它:

def self.run
  puts "toto"
end

如果不需要将该方法作为class的自方法,您可以这样做。

 every 1.minutes do
   runner "Crawler.new.run", :output => '/Users/bl0b/Projects/crawler/cron.log'  
 end

相关内容

  • 没有找到相关文章

最新更新