I'm new to ruby and just trying to toech myself ruby on rails. I've got a shopping cart and I need to be able te specify product quantity while in the cart. I have succefully created a link to incriment the quantity but I would like to be able to grab a number from a text_field and use it as the new quantity. The incriment feature is implimented as follows:
This is in my view: <%= link_to("<font color=green>(add)</font>", :action => :update_cart, :id => product.id) %>
This is in my store controller: def update_cart product = Product.find(params[:id]) @cart.update_product(product) flash[:notice] = "Item quantity has been updated" redirect_to(:action => :display_cart) end
This is in my cart class: def update_product(product) item = @items.find {|i| i.product_id == product.id} item.quantity += 1 @total_price += product.price @total_shipping += product.shipping end
I'm clueless here and could really use some help. TIA