【发布时间】:2015-12-23 09:20:30
【问题描述】:
我在尝试将每个 boxes.percent 与局部变量 percent 相加时遇到此错误。
这里是错误:
Fixnum 没有隐式转换为数组
我的代码:
<% percent = 0, shares = 0 %>
<% @modification.boxes.each do |d|
percent = percent + d.percent #here is problem, at least rails told me that
shares = shares + d.shares
end %>
<% unless percent == 100 %>
Total percent needs to be 100%!
<% end %>
<% unless shares == @modification.entity.total_number %>
Not correct number!
<% end %>
问题出在哪里?在数据库中,框的 percent 和 shares 都是整数。
【问题讨论】:
-
解释一下这些变量/方法是什么。
-
共享堆栈跟踪,从顶部开始至少几行
-
@sawa
d.percent和d.shares是每个box的百分比和份额计数。都是 DB 中的整数。局部变量percent和shares用于将所有内容一起计算。我解释过你想要什么吗? -
如何创建
@modification以及boxes方法的外观如何? -
@modification 是数据库表。每个修改都有很多框。所以它们都是数据库表。