Ever wondered about the Calculations in Rails, I used to use the group_by in SQL or select to do many calculations while fetching the results , but sometimes Rails doesnt allow to use group etc , like when we are doing AJAX calls in v2.1.0 of rails .
Then Joejeet helped me to get the following calculations methods , it was so beautiful that my 3 line of code was convered to 1 single line.
@rating_sum = Rating.sum(’rating’, :conditions =>[“rateable_id = ? and rateable_type = ?”, @rating.rateable_id, @rating.rateable_type])
There are other methods like Avg,minimum, max,count etc available under