The error comes, because the num
variable is nil
in some cases. number_to_currency(nil)
works, because the helper is implemented like this:
def number_to_currency(number, options = {})
return unless number
...
end
source: http://apidock.com/rails/ActionView/Helpers/NumberHelper/number_to_currency
You see, a nil
doesn't hurt here, because it will instantly return.
Your function, however, tries to execute nil / 100.0
first. As the error states, the /
method is not defined on nil
.
You probably need some special nil
treatment, or hunt the cases when nil
is given to your helper.