summarizer
Summary
In the model:
class Foo < ActiveRecord::Base
include Summarizer::Base # add Summarizer to your class
summarize :net, :gross # which columns/methods do you want to sum up?
end
In the controller:
# find_with_sums extends ActiveRecord.find
@foos = Foo.find_with_sums(:all, :order => 'created_at',
:split_sections_on => Proc.new {|a,b| a.at.month != b.at.month},
:section_label => Proc.new{|obj| obj.at.strftime("%B %Y")})
In the view:
| <%=h foo.created_at %> | <%=h foo.name %> | <%=h foo.gross %> | <%=h foo.net %> |
The partials _index_section_header.html.erb
and _index_sum.html.erb
In the Browser:
November 2009
2009-11-29 03:32:27 Blah 160.46 91.25
Total 160.46 91.25
December 2009
2009-12-04 01:32:45 Blub 130.42 122.24
2009-12-05 18:02:33 Bar 77.53 135.57
2009-12-15 21:19:25 Blah 175.32 150.42
2009-12-31 17:21:49 Baz 192.05 135.04
Total 575.32 543.27
January 2010
2010-01-08 18:26:48 Blub 116.14 151.22
Total 116.14 151.22
----------------------------------------------
Total 851.92 785.74
Usage
Soon to come...
Copyright
Copyright (c) 2010 Christoph Petschnig. See LICENSE for details.