Sum All Order function in Ruby

Member

carey

by carey , in category: Ruby , a month ago

Sum All Order function in Ruby

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
def sum_all_orders
    sum = 0
    Order.where(user_id: self.id).each do |order|
      sum = sum + order.total_sum
    end
    sum
  end

  # вместо
  def sum_all_orders
     orders.sum(&:total_sum)
  end


Facebook Twitter LinkedIn Telegram Whatsapp Pocket

no answers