How to add multiple items to a cart

Hi Elle,

The first step is to get your model to allow adding many items with a specified amount. In card.rb:

def add(product_id, amount = 1) # By setting the default to one, # if no amount is specified, the method is still the same   items = cart_items.find_all_by_product_id(product_id)   product = Product.find(product_id)

   if items.size < 1      ci = cart_items.create(:product_id => product_id,                                             :amount => amount,                                             :price => product.price)    else      ci = items.first      ci.update_attribute(:amount, ci.amount + amount)    end    ci end

Now we need to get it to the controller action. Change @item = @cart.add(params[:id]) to @item = @cart.add(params[:id], params[:amount])

Last step is to add a text box to the form. It looks like it would go in the cart/item partial (no listed here?) but basically needs to look like this inside your form:

<%= text_box_tag "amount", 1 %>

Good Luck, Rob