I have a Seller model that has_many Items.
I want to get the total sale price of all of a Seller\'s items.
In seller.rb I have
def total_item
One way is:
items.to_a.sum { |e| e.sale_price.to_i } # or to_f, whatever you are using
Methods like #to_f and #to_i will turn nil into 0.
#to_f
#to_i
nil
0