Frage

I have an instance variable @balance = 300 that I would like to automatically add 300 to its value each month (or 30 days). How would I go about doing this in rails?

War es hilfreich?

Lösung 2

I suggest storing it somewhere in the database, using a gem like

sidekiq

Railscast for it

or

https://www.ruby-toolbox.com/categories/Background_Jobs

Any of these.

Andere Tipps

You can use a scheduler, sidekiq or cron job, if you are using heroku then there is an easy scheduler call heroku scheduler.

Just make a rake task with code like this:

if Time.now.day == 1 
  @balance += 300
end

And set the scheduler to use this task everyday. If you are not using heroku, then you will have to implement a cron job.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top