Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 优点宝石:如何抓住用户';一天的积分是多少?_Ruby On Rails 4_Points_Merit Gem - Fatal编程技术网

Ruby on rails 4 优点宝石:如何抓住用户';一天的积分是多少?

Ruby on rails 4 优点宝石:如何抓住用户';一天的积分是多少?,ruby-on-rails-4,points,merit-gem,Ruby On Rails 4,Points,Merit Gem,我如何使用价值宝石获取用户一天(即“今天”或“昨天”)的积分 我试过: current_user.points.where("created_at >= ?", Time.zone.now.beginning_of_day) 但这是行不通的。有一个模型图,显示了该模型的优点。考虑到这一点,像这样的行使它工作: user = User.first points = user.sash.scores.first.score_points points.where("created_at &g

我如何使用价值宝石获取用户一天(即“今天”或“昨天”)的积分

我试过:

current_user.points.where("created_at >= ?", Time.zone.now.beginning_of_day)

但这是行不通的。

有一个模型图,显示了该模型的优点。考虑到这一点,像这样的行使它工作:

user = User.first
points = user.sash.scores.first.score_points
points.where("created_at > '#{Time.zone.now.beginning_of_day}'")

这是最后的答案:

u.sash.scores.first.score_points.where("created_at > ?", Time.zone.now.beginning_of_day).sum(:num_points)

谢谢图泰克。

我想你应该看看宝石的来源。例如,它返回数字!但您可以看到,这个数字是查询
得分的结果。我认为如果您设法在表中添加一个范围
score\u points
,您就有机会获得一天的积分。也许你可以覆盖整个方法
points
。我得到了如下完整的结果:u.sash.scores.first.scores\u points.where(“created\u at>?”,Time.zone.now.start\u of\u day)。sum(:num\u points)