Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想计算一列中值的总和。例如:
@items = Item.find_all_by_cart_id(cart)
项目有列数量。我想要@items 数量的总和。
items_quantity = @items.map(&:quantity).sum
尝试这个
@items = Item.find_all_by_cart_id(cart).sum(:quantity)