yejielw
yejielw

Reputation: 19

How to run a code once a week, every sunday for exaple, im using Rails 4.2.5 and ruby 2.3

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

Answers (2)

Guy Dubrovski
Guy Dubrovski

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

Maxim Zubarev
Maxim Zubarev

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

Related Questions