Reputation: 19
i need to show a random item from an array that changes once a week. I'm getting the random item like this.
<% @item.sample(1).each do |item| %>
It works just fine but it makes the change everytime the page is reloaded.
What do i need to do for the code to run once a week?
Upvotes: 0
Views: 176
Reputation: 1560
If you are using Heroku, you can use the Heroku Scheduler https://devcenter.heroku.com/articles/scheduler
It can save you some glue code and just write your logic.
Upvotes: 0
Reputation: 2473
You want cronjobs. A ruby library doing this that you can incorporate into your Rails project would be https://github.com/javan/whenever
Upvotes: 2