# Capture form input from text\_field and modify data

**URL:** <https://www.ruby-forum.com/t/capture-form-input-from-text-field-and-modify-data/118331>\
**Category:** Rails\
**Created:** [October 25, 2007, 7:54pm UTC](https://www.ruby-forum.com/t/capture-form-input-from-text-field-and-modify-data/118331 "2007-10-25T19:54:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 25, 2007, 7:54pm UTC](https://www.ruby-forum.com/t/capture-form-input-from-text-field-and-modify-data/118331/1 "2007-10-25T19:54:37Z")

</div>

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("(add)", :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
