我正在测量多个参数的平均值。对于1个独特的参数,所有作品都完美无缺,但我无法平均做多个参数。你可以帮我吗 ?多个参数的全球平均值
@ratingservice = Comment.where(:camping_id => params[:id]).average(:service).to_i
@ratingcommunication = Comment.where(:camping_id => params[:id]).average(:communication).to_i
@ratingqualiteprix = Comment.where(:camping_id => params[:id]).average(:qualiteprix).to_i
@ratinganimation = Comment.where(:camping_id => params[:id]).average(:animation).to_i
@ratingproprete = Comment.where(:camping_id => params[:id]).average(:proprete).to_i
@ratingsituation = Comment.where(:camping_id => params[:id]).average(:situation).to_i
对于多PARAMS该命令不工作:未初始化不断
@ratingall = Commment.where(:camping_id => params[:id]).average(:service, :communication, :qualiteprix, :animation, :proprete, :situation).to_i
通过这种方法是不燥肯定的方式....
个人而言,尚未尝试过。 'Comment.where(:camping_id => params [:id])。group(:service,...)'看看返回的东西然后得到总和/平均等...让我知道! – 7urkm3n