1

当我尝试从搜索结果中平均一列时出现错误:

undefined method `each' for #<BigDecimal:101780440,'0.1776030511 706048E4',27(45)>

看法

<% @vone.each do |v| %>
<%= "%.2f" % (v.lint/227) %>
<% end %>

控制器

@vone = Result.where(params[:variety_one], params[:years]).includes(:trial).where(params[:region_id], params[:irrigated]).average('lint')
4

1 回答 1

2

方法“平均”返回数字,因此它不响应“每个”方法

http://api.rubyonrails.org/classes/ActiveRecord/Calculations.html#method-i-average

如果要遍历结果,则应删除平均值

@vone = Result.where(params[:variety_one], params[:years]).includes(:trial).where(params[:region_id], params[:irrigated])
于 2013-11-01T02:05:27.460 回答