Reputation: 1395
I have a Subscription table that has plan_id and updated_at column. I can't figure out how to show the current user has x amount of days until subscription has ended.
plan_id 1 is a 30 day subscription. plan_id 12 is a 12 month subscription.
Has someone done something similar to this?
Upvotes: 0
Views: 96
Reputation: 771
Add a 'duration' column to the Plan model and set to appropriate number of days
i.e. 30 or 365
Add an expires_at method to your subscription:
class Subscription ...
def expires_at
self.created_at + plan.duration.days
end
end
Use 'distance_of_time_in_words' to render appropriate text:
distance_of_time_in_words(Time.now, subscription.expires_at)
Here is a link to the helper method:
Upvotes: 1