I have a method to calculated the average for a given set of records:
input = params[:recommendation_ratings].values # The params are sent from radio_tags in my view.
input.each do |mini_params|
rating_id = mini_params[:rating_id]
l = Rating.find(rating_id) #Find record on Rating table.
l.rating #Get value associated with rating_id
total_rating = []
total_rating << l.rating
average = total_rating.inject{ |sum, el| sum + el }.to_f / total_rating.size
puts average
end
l.rating is not being appended to the total_rating array. The puts average is being printed as:
3.0
3.0
3.0
3.0
3.0
How do I append each of the ratings being returned to the array to calculated the average,and other math functions.