开发者

How can I add the values of integer fields across records and divide by the number of records?

I have a table of review records where one of the fields (rating, a number 1 to 5) is an integer and they are displayed as partials on their assigned venue show page.

How can I show on the venue show page the total of all the ratings from all its reviews divided by the number of reviews it has?

I get the total number of r开发者_高级运维eviews written for the venue with:

 <%= @venue.reviews.count %>

Thanks for any help its much appreciated!


@venue.reviews.average(:rating)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜