Sum of points for last seven days

Hey guys,

im very very stuck trying to figure out how to go about implementing a
sum method to sum up the points a user gained for each day of the

create_table “user_point_logs”, :force => true do |t|
t.column “user_id”, :integer
t.column “points”, :integer
t.column “created_at”, :datetime

I want to be about to simply calculate the total points the user
gained for the last seven days.

I got this so far.
@statistics = @current_user.user_point_logs.find(:all,
:conditions => [‘created_at > ?’, 7.days.ago])


can any provided me some snippets to help me out?



i made some improve if anyone can improve on it more to help me,

i got this so far

@stats = @current_user.user_point_logs.sum(:points, :group =>

but i want to fine tune it to work only for the last 7 days

no worries !!

thanks all good, worked it out

for your interests…

@stats = @current_user.user_point_logs.sum(:points,
  :group => 'date(created_at)',
  :conditions => ['created_at > ?', 7.days.ago])

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs