sum decimals

40 views
Skip to first unread message

Werner

unread,
Oct 26, 2012, 8:18:50 AM10/26/12
to rubyonra...@googlegroups.com
I have a column "hours" which I want to sum up the decimals

Week.sum('hour')    => 22.5

But I want to "select by project_id" not the hole table.
Week.find_all_by_project_id(@project.id, :select => "workhour").sum  #undefined method `+' for #<Week hour: #<BigDecimal:7fd68b358400,'0.0',9(18)>>

I cant find anything ...some help would be great.

Rob Biedenharn

unread,
Oct 26, 2012, 10:52:43 AM10/26/12
to rubyonra...@googlegroups.com
You left the argument out of the .sum (i..e, .sum('hour') on the second one)

I think that you just need this:

Week.where(project_id: @project_id).sum('hour')


-Rob

Werner

unread,
Oct 26, 2012, 11:34:32 AM10/26/12
to rubyonra...@googlegroups.com
Thanks Rob.. true.. it works as expected..
Reply all
Reply to author
Forward
0 new messages