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?
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.
I'm not familiar with Merit, so you'll have to look at what models it gives you, but you can probably do something like this in your user model:
class User < ActiveModel::Base
def validPonts
self.points.select{ |p| p.created_at > 180.days.ago }
end
end
and then you call @user.validPoints to retrieve only the points that exist from the last 180 days.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.