Reputation: 15394
I have an app that allows you to upload a recipe to the db, as part of the app i would like to have a "Featured Recipe" that is called randomly from the recipe db. I am using this method to call a random record
@featurerecipe = Recipe.offset(rand(Recipe.count)).limit(1)
As expected when i refresh the page the record changes, however I would like the random record to stay in place for say 24 hours, even when the page is refreshed. I'm looking for some advice on how to go about this or perhaps someone else has done this in a project of their own? I was thinking that you could have a db column called feature and then set a "true" value to it, set everything else as false and then somewhere a loop needs to occur to check the time spent at value "true", then after 24 hours pick another random recipe?
I may be well off here, any help appreciated
Upvotes: 0
Views: 52
Reputation: 51
As you mentioned, add a "featured" flag to the table. Setup resque/resque-scheduler or delayed job to run every 24 hours and select a new item at random.
Upvotes: 1