We Recommend

The Rails Way The Rails Way
Now, for the first time, there’s a comprehensive, authoritative guide to building production-quality software with Rails. Pioneering Rails developer Obie Fernandez and a team of experts illuminate the entire Rails API, along with the Ruby idioms, design approaches, libraries, and plug-ins that make Rails so valuable.


Posted By

winson on 04/30/07


Tagged

textmate model cart


Versions (?)


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.