nachime
nachime

Reputation: 1856

How should I check if an expiry date has expired?

For example, I want current_user.subscribed to be changed to false if current_user.expiry_date is of a date before Date.today.

I don't actually know to implement this. Which controller or action should I link this to (if I should at all?). Is there a way to have this automatically happen?

Upvotes: 0

Views: 2099

Answers (2)

bk chovatiya
bk chovatiya

Reputation: 223

Try this:

subscribed = Date.today < current_user.expiry_date

It will return false if user date is expiry.

Upvotes: 1

davidhu
davidhu

Reputation: 10462

A good place to implement this would be in the method that logs in the user. You can check the expiry_date against Date.today

current_user.subscribed = false if Date.today > current_user.expiry_date

Upvotes: 0

Related Questions