Question

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?

Était-ce utile?

La solution 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.

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top