Can I schedule controller methods in rails using rufus-scheduler?
问题 Could I schedule the index method from the controller posted below? If so, how would I go about doing that? class WelcomeController < ApplicationController def index if Number.find(1) @number = Number.first @number.value += 1 @number.save else @number = Number.new @number.value = 0 end end end 回答1: So you seem to have a Number model. The first step would be to move your logic from the controller to the model: class Number def self.increment n = nil if Number.find(1) n = Number.first n.value +