Answer the question
In order to leave comments, you need to log in
How to replace the ternary operator?
There is a code like this:
margin = @supply.supplier.margin ? @supply.supplier.margin : 0
Answer the question
In order to leave comments, you need to log in
@supply.supplier.margin || 0
It will not give you what you want when the margin is equal ""
(what happens if you change it to an empty value through the form)
For this, they made a method in Rails.
Which is equivalent to:
present? checks for empty values better than implicit type casting
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question