Pregunta

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?

¿Fue útil?

Solución 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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top