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
week.
schema:
  create_table "user_point_logs", :force => true do |t|
    t.column "user_id",      :integer
    t.column "points",       :integer
    t.column "created_at",   :datetime
  end
I want to be about to simply calculate the total points the user
gained for the last seven days.
I got this so far.
controller:
    @statistics = @current_user.user_point_logs.find(:all,
      :conditions => [''created_at > ?'', 7.days.ago])
view:
   @statistics.sum(&:points)
can any provided me some snippets to help me out?
regards,
Chubbs
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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 => ''created_at'') but i want to fine tune it to work only for the last 7 days On Jan 10, 6:45 pm, Chubbs <acetin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > week. > > schema: > create_table "user_point_logs", :force => true do |t| > t.column "user_id", :integer > t.column "points", :integer > t.column "created_at", :datetime > end > > I want to be about to simply calculate the total points the user > gained for the last seven days. > > I got this so far. > controller: > @statistics = @current_user.user_point_logs.find(:all, > :conditions => [''created_at > ?'', 7.days.ago]) > > view: > @statistics.sum(&:points) > > can any provided me some snippets to help me out? > > regards, > > Chubbs--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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])
On Jan 10, 6:58 pm, Chubbs
<acetin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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 =>
> ''created_at'')
>
> but i want to fine tune it to work only for the last 7 days
>
> On Jan 10, 6:45 pm, Chubbs
<acetin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > 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
> > week.
>
> > schema:
> >   create_table "user_point_logs", :force => true do |t|
> >     t.column "user_id",      :integer
> >     t.column "points",       :integer
> >     t.column "created_at",   :datetime
> >   end
>
> > I want to be about to simply calculate the total points the user
> > gained for the last seven days.
>
> > I got this so far.
> > controller:
> >     @statistics = @current_user.user_point_logs.find(:all,
> >       :conditions => [''created_at > ?'',
7.days.ago])
>
> > view:
> >    @statistics.sum(&:points)
>
> > can any provided me some snippets to help me out?
>
> > regards,
>
> > Chubbs
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---