Rails:每天在特定时间重置模型属性 [英] Rails: Reset a model attribute at specific time each day

查看:79
本文介绍了Rails:每天在特定时间重置模型属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有Location模型的Rails应用程序,该模型具有一个rating和一个rating_count字段.现在,我需要每天在特定时间将每个Locationratingrating_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_countattributes 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆