ruby-on-railsrubymerit-gem

Merit Gem: expiring points


I'm giving discounts on products based on user's point total. But I would like to encourage users to use those points within 180 days. So, only points created_at < 180.days.ago would count.

What would be a simple way to get the only punctuation from 180 days ago?


Solution

  • It seems too late but now I'm working on similar situation and I find this example in their own documents.

    https://github.com/tute/merit#other-actions-1

    In your case code would be something like this.

    user.score_points.where("created_at > '#{180.days.ago}'").sum(:num_points)
    

    Apparently, #points returns mere integer (not a Point object). So if you wanted to pick and choose points with their given date, you need to use #score_points instead.

    I hope this helps.