Reputation: 485
I want to calculate the sum of the values in a column. For example:
@items = Item.find_all_by_cart_id(cart)
Item has column quantity. I want the sum of the @items quantity.
Upvotes: 0
Views: 727
Reputation: 2638
Try this
@items = Item.find_all_by_cart_id(cart).sum(:quantity)
Upvotes: 1
Reputation: 25761
items_quantity = @items.map(&:quantity).sum