2017-03-09 67 views
0

任何人都可以解釋這個錯誤嗎?嘗試在ERB文件中分割和減去。我相信最好的做法是在控制器中做,但寧可不行。ActionView :: Template :: Error(THING不能被強制轉換爲Fixnum):

  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 %> 
+2

什麼'call.has_fee'的價值?看起來像它的布爾值 –

+1

您是否嘗試將其轉換爲整數befor進行計算,ruby中的.to_i方法。這是非常基本的,但這是我唯一的想法 –

回答

1

pricecall.has_fee返回一個AcctLedger對象,通過任何機會呢?這個錯誤是說AcctLedger不知道如何像數字一樣行事,但是你正在嘗試在計算中使用它。

你可以看到類似的事情,如果你嘗試添加一個數字和字符串:

1 + '1' 
# TypeError: String can't be coerced into Fixnum 
相關問題