I am having trouble with getting the sum of all impressions for a specific object that relates to a user within a 24 hour span. Basically, I want to count the daily impressions for the current_user's posts.
I tried six or seven different approaches, but none work. My latest is the one below.
def posts_daily_impressions_count(current_user)
current_user.posts.sum(&:impressionist_count).group_by_day(:created_at)
end
You can solve this problem by tracking only the posts created within the day/month/year.
Create the scopes for the posts
Apply them before the sum method
This will give you the impressions that were created within the span of time that you're focusing on.