6

我随时都在使用 gem ,但我的跑步者指令无法正常工作。

我收到此错误:

/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
4

2 回答 2

9

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

def self.run
  puts "toto"
end
于 2013-02-05T15:02:38.633 回答
1

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

 every 1.minutes do
   runner "Crawler.new.run", :output => '/Users/bl0b/Projects/crawler/cron.log'  
 end
于 2013-05-03T05:46:02.057 回答