Undefined method with rails runner
Asked Answered
S

2

6

I'm using the gem whenever and I can't get my runner instruction working.

I'm getting this error:

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

I have the following code in my shedule.rb :

set :environment, 'development' 

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

and in my app/models/crawler.rb I have the following code:

class Crawler < ActiveRecord::Base

  def run
    puts "toto"
  end

end
Serapis answered 5/2, 2013 at 15:0 Comment(0)
D
9

You are attempting to call a class method on Crawler, but the method is defined as an instance method. To make your method a class method you can define it like so:

def self.run
  puts "toto"
end
Dilapidated answered 5/2, 2013 at 15:2 Comment(0)
R
1

You can do like , If you don't need to make the method as a self method of the Class.

 every 1.minutes do
   runner "Crawler.new.run", :output => '/Users/bl0b/Projects/crawler/cron.log'  
 end
Reef answered 3/5, 2013 at 5:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.