如何每天将日期时间设置为Date.current?

时间:2016-02-18 21:33:31

标签: ruby-on-rails ruby

我试图找出一种模型方法,使nil截止日期变为Date.current

我希望deadline在每天开始时刷新到Date.current

challenge.rb

def deadline_current
  self.deadline == Date.current  # How to trigger something like this at the start of each day and upon the creation of a new challenge?
end

1 个答案:

答案 0 :(得分:1)

如果我理解正确,我认为最好的方法是设置一个每天运行的cron作业。为此,我建议使用gem whenever

every 1.day, :at => '0:00 am' do
runner "Challenge.deadline_current"
end