選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

14 行
324 B

  1. class Cart < ApplicationRecord
  2. has_many :line_items, dependent: :destroy
  3. def add_product(product)
  4. current_item = line_items.find_by(product_id: product.id)
  5. if current_item
  6. current_item.quantity += 1
  7. else
  8. current_item = line_items.build(product_id: product.id)
  9. end
  10. current_item
  11. end
  12. end