Posted By

winson on 04/30/07


Tagged

textmate model cart


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

webstic
octoberborn


My add book to cart in model


 / Published in: Rails
 

  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  

You need to login to post a comment.