AR has a sum function. On Fri, Sep 10, 2010 at 4:45 AM, Fidel Viegas <fidel.vie...@gmail.com>wrote:
> Hi everyone, > > I am trying to a cumulative sum on each page using will_paginate. I > don't want the sum of each page, but the cumulative sum. Here is an > example: > > on Page 1 I have: > > ----------------------------------------------------------------- > | date | in | out | balance | > ----------------------------------------------------------------- > |12-03-2010| 23.0 | 0.0 | 23.0 | > ----------------------------------------------------------------- > |12-03-2010| 23.0 | 0.0 | 46.0 | > ----------------------------------------------------------------- > |12-03-2010| 43.0 | 0.0 | 89.0 | > ----------------------------------------------------------------- > |12-03-2010| 53.0 | 0.0 | 142.0 | > ----------------------------------------------------------------- > |12-03-2010| 0.0 | 26.0 | 116.0 | > ----------------------------------------------------------------- > |12-03-2010| 25.0 | 0.0 | 141.0 | > ----------------------------------------------------------------- > |12-03-2010| 0.0 | 17.0 | 124.0 | > ----------------------------------------------------------------- > |12-03-2010| 0.0 | 25.0 | 99.0 | > ----------------------------------------------------------------- > |12-03-2010| 33.0 | 0.0 | 132.0 | > ----------------------------------------------------------------- > Total | 200.0 | 68.0 | 132.0 | > ----------------------------------------------------------------- > > On page 2 I have: > > ----------------------------------------------------------------- > | date | in | out | balance | > ----------------------------------------------------------------- > |12-03-2010| 23.0 | 0.0 | 155.0 | > ----------------------------------------------------------------- > |12-03-2010| 0.0 | 45.0 | 110.0 | > ----------------------------------------------------------------- > |12-03-2010| 43.0 | 0.0 | 153.0 | > ----------------------------------------------------------------- > |12-03-2010| 53.0 | 0.0 | 206.0 | > ----------------------------------------------------------------- > Total | 319.0 | 113.0 | 206.0 | > ----------------------------------------------------------------- > > etc, etc,etc.... > > Has anyone done something similar to this before using ActiveRecord > and will_paginate? > > I look forward to hearing from you some suggestions. > > Regards, > > Fidel. > > -- > 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-t...@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com<rubyonrails-talk%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.