[英]Merit Gem: expiring points
我會根據用戶的總積分給予產品折扣。 但我想鼓勵用戶在180天內使用這些積分。 因此,只有點created_at <180.days.ago要計入。
從180天前獲得唯一標點的簡單方法是什么?
似乎為時已晚,但現在我正在處理類似的情況,並且可以在自己的文檔中找到此示例。
https://github.com/tute/merit#other-actions-1
在您的情況下,代碼將是這樣的。
user.score_points.where("created_at > '#{180.days.ago}'").sum(:num_points)
顯然, #points
僅返回整數(不是Point對象)。 因此,如果要選擇給定日期的點,則需要改用#score_points
。
我希望這有幫助。
我對Merit不熟悉,因此您必須查看它所提供的模型,但是您可以在用戶模型中執行以下操作:
class User < ActiveModel::Base
def validPonts
self.points.select{ |p| p.created_at > 180.days.ago }
end
end
然后調用@ user.validPoints以僅檢索過去180天中存在的點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.