Ruby on rails - Static method

后端 未结 6 516
青春惊慌失措
青春惊慌失措 2020-12-09 07:31

I want a method to be executed every 5 minutes, I implemented whenever for ruby (cron). But it does not work. I think my method is not accessible. The method I want to exec

6条回答
  •  青春惊慌失措
    2020-12-09 08:03

    Change your code from

    class MyModel
      def checkPings
      end
    end
    

    to

    class MyModel
      def self.checkPings
      end
    end
    

    Note there is self added to the method name.

    def checkPings is an instance method for the class MyModel whereas def self.checkPings is a class method.

提交回复
热议问题