My add book to cart in model


/ Published in: Rails
Save to your folder(s)



Copy this code and paste it in your HTML
  1. def add(book)
  2. cur_item = cart_items.find_by_book_id(book.id)
  3. new_item = cart_items.new(:book_id => book.id, :price => book.price, :amount => 1)
  4. cur_item ? (cur_item.amount += 1; cur_item.save) : cart_items << new_item
  5. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.