ActionView::Template::Error(不能将 THING 强制转换为 Fixnum):

ActionView::Template::Error (THING can't be coerced into Fixnum):

谁能解释一下这个错误?尝试在 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 %> 

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

如果你尝试添加一个数字和一个字符串,你会看到类似的东西:

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