开发者

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

开发者 https://www.devze.com 2023-02-22 09:02 出处:网络
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.

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

精彩评论

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