例如,我有一个 Controller “帖子”和操作“创建”。我可以从终端运行它吗?
我想使用 whenever
gem:
every 2.hours do
# I want to run posts#index
end
我该怎么做?
最佳答案
一个解决方案是创建一个执行 create
逻辑的类:
class PostsController < ApplicationController
def create
creator = PostCreator.new(params)
creator.process
end
end
所以你可以在 Whataver
的工作中使用这个类:
every 2.hours do
creator = PostCreator.new({ whatever: 'you want'})
creator.process
end
关于ruby-on-rails - 如何在 Rails 中使用 whenever gem 运行 Controller 操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28429143/