Update quantity

Hi,

I added a field to my cart that allows you to update the quantity of
the item but when I try to update the quantity I get an error:

NoMethodError in CartController#update
undefined method `update_attribute' for #<Array:0x3464698>

app/models/cart.rb:33:in `update'
app/controllers/cart_controller.rb:53:in `update'
Request
Parameters: {"qty_update"=>"3", "id"=>"2"}

cart_items.find_all_by_product_id(product_id)

will certainly return an array, not a cart item object… you might use

cart_items.find_all_by_product_id(product_id).first

bye

will certainly return an array, not a cart item object... you might use
cart_items.find_all_by_product_id(product_id).first

When I changed that, I now get this error:

NameError in CartController#update
undefined local variable or method `product' for #<CartController:
0x31795c8>

app/controllers/cart_controller.rb:54:in `update'
Request
Parameters: {"qty_update"=>"4", "id"=>"2"}

My cart_controller.rb is:
49 def update
50 @product = Product.find(params[:id])
51 qty_update = params[:qty_update]
52 if request.post?
53 @cart.update(params[:id], qty_update)
54 flash[:notice] = "Updated <em>#{product.title}</em>"
55 redirect_to :action => "view_cart"
56 end
57 end

Any ideas?

TIA,
Elle

Actually, changing it from @product to product and then changing this
line: @cart.update(product, qty_update) -- fixed it :slight_smile:

Thanks.
Elle