Rails:使用时间引用设置模型属性



1。环境

我有一个具有以下属性的拍卖模型:

  • 状态:字符串
  • close_date:日期时间

Time.now时,我的拍卖状态必须自动设置为"结束"等于auction.close_date。要做到这一点,我想我需要一种每秒钟都能检查这种平等的方法。

这是我的方法:


def set_ended
  auctions = Auction.all.active # named_scope to get only 'active' auctions
  auctions.each do |auction|
    if auction.close_date == Time.now
      auction.status = 'ended'
    end
end

2.问题:

如何将我的应用程序设置为每秒运行此方法?

看看Where,这就是您所需要的。

最新更新