John Trichereau
John Trichereau

Reputation: 626

Merit Gem: how to grab a User's points for a single day?

How can I grab a User's points for a single day (i.e. 'Today' or 'Yesterday') using the Merit gem?

I tried:

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

but that doesn't work.

Upvotes: 0

Views: 167

Answers (2)

John Trichereau
John Trichereau

Reputation: 626

This is the final answer:

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

Thanks TuteC.

Upvotes: 0

TuteC
TuteC

Reputation: 4382

There's a models diagram for merit in https://github.com/tute/merit/wiki/General-merit-workflow. With that in mind, lines like this makes it work:

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

Upvotes: 1

Related Questions