if products.nil?
products.first.total_amount
else
0.0
end
There is a cleaner way to achieve the same result:
products.first.try(:total_amount) || 0.0
passionate hackers in Hong Kong. Agile, Ruby On Rails, Scala and Pen Test
if products.nil?
products.first.total_amount
else
0.0
end
products.first.try(:total_amount) || 0.0