I have what should be a simple operation where I want to calculate the percentage completion of something in Rails 3.
In my Object model, I have the following function:
def balance
(self.amount_remaining / self.amount) * 100
end
开发者_Python百科Then, in my Object view, I have the following:
<%= Object.balance %>
However, I get the following error:
undefined method `/' for nil:NilClass
Does anyone know what may be causing this error? Should I be making this calculate elsewhere?
Like this?
(self.amount_remaining / self.amount) * 100 rescue 0
精彩评论