ActionView :: Template :: Error(THING无法强制进入Fixnum):

时间:2017-03-09 06:29:49

标签: ruby-on-rails erb

任何人都可以解释这个错误吗?尝试在ERB文件中进行分割和减法。我确信最佳做法是在控制器中进行,但不愿意。

            ActionView::Template::Error (AcctLedger can't be coerced into Fixnum): 
        Mar 09 00:25:34 myapp app/web.2:      107:  
        Mar 09 00:25:34 myapp app/web.2:      108:         <% if "myapp XL" == call.requested_type %> 
        Mar 09 00:25:34 myapp app/web.2:      109:           <% if call.has_fee? %> 
        Mar 09 00:25:34 myapp app/web.2:      110:             <% price = (price - call.has_fee)/2 %> 
        Mar 09 00:25:34 myapp app/web.2:      111:           <% else %> 
        Mar 09 00:25:34 myapp app/web.2:      112:             <% price = price/2 %> 
        Mar 09 00:25:34 myapp app/web.2:      113:           <% end %> 

1 个答案:

答案 0 :(得分:1)

pricecall.has_fee是否有机会返回AcctLedger个对象?此错误表示AcctLedger不知道如何像数字一样操作,但您正在尝试在计算中使用它。

如果您尝试添加数字和字符串,则可以看到类似的内容:

1 + '1'
# TypeError: String can't be coerced into Fixnum