Rails:每天在特定时间重置模型属性 [英] Rails: Reset a model attribute at specific time each day
问题描述
我有一个带有Location
模型的Rails应用程序,该模型具有一个rating
和一个rating_count
字段.现在,我需要每天在特定时间将每个Location
的rating
和rating_count
属性重置为0,比如说UTC 12:00:00.
I have a rails app with a Location
model, which has a rating
, and a rating_count
field. Now, I need to reset every Location
's rating
and rating_count
attributes to 0 at a specific time everyday, lets say 12:00:00 UTC.
我该怎么做?我正在使用默认的sqlite3
数据库.
How would I accomplish this? I'm using the default sqlite3
databases.
推荐答案
最好的选择是使用cron.您可以在那里找到大量的文档.尽管如果您正在运行Rails应用,则应该查看何时一个非常漂亮的宝石,可以为您的应用程序管理cron作业!
The best option is to use cron. You can find tons of documentation out there!Although if you are running a Rails app you should check out whenever a pretty neat gem for managing cron jobs for your app!
这篇关于Rails:每天在特定时间重置模型属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!