salols
salols

Reputation: 89

Changing a objects attribute after a certain period of time? Rails

I have an app that allows users to sign up. However, some users don't fully complete the sign up process, which relegates them to the status of inactive. After 30 days, if said user is still inactive, I'd like for their status to change to dormant. I'm new to this so if you need anymore information please ask. Thanks!

Upvotes: 1

Views: 612

Answers (1)

MrYoshiji
MrYoshiji

Reputation: 54882

As @jmm pointed out, you can use the Whenever gem (https://github.com/javan/whenever) and set up a daily job:

# config/schedule.rb
every 1.day, at: '4:00 AM' do
  dormant_users = User.where(status: 'inactive').where('created_at < ?', 30.days.ago)
  dormant_users.update_all(status: 'dormant')
end

This code is an example, you might not handle the status of User the way I suggested.

Upvotes: 1

Related Questions