Re: [Rails] sum decimals
Thanks Rob.. true.. it works as expected..
Am Freitag, 26. Oktober 2012 16:53:13 UTC+2 schrieb Rob Biedenharn:
--
On Oct 26, 2012, at 8:18 AM, Werner wrote:
> 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.
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
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/ArlTq3t-m7gJ.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home