开发者

Rails 3: How can I automate the creation of objects in my DB once a day?

I'm diving into Rails for the first time and I'm creating a Rails 3 app, hosted on Heroku, to manage tournaments and currently I'm creating them manually once a day through my web interface. I'd like to automate the creation of these tournament objects once a day rather than manually create them through the web interface. I was wondering what the standard practice is for this kind of automation.

One way I could do this is check to see if it's time to create a ne开发者_Python百科w tournament object whenever a specific method is called in one of my controllers. In other words, since users periodically request information for upcoming tournaments throughout the day, I could add some code to the method the returns that info and check if it's time to create a new tournament. For some reason, even with my beginner knowledge of Rails, this feels hackish, probably because it's poorly dependent upon someone requesting info about upcoming tournaments in order for the creation to take place.

Should I somehow use cron jobs for this?


Heroku has a free addon called Daily Cron which allows you to create a Rake task called cron that will be run once a day automatically. Simply create the tournament in this task.

Some info on Rake tasks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜