BigDecimal未定义的方法

时间:2013-11-01 01:49:09

标签: ruby-on-rails ruby-on-rails-3.2

当我尝试从搜索结果中平均列时,我收到错误:

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')

1 个答案:

答案 0 :(得分:2)

方法'average'返回数字,因此它不响应'each'方法

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])