# Proper syntax for text field (less garbled)

**URL:** <https://www.ruby-forum.com/t/proper-syntax-for-text-field-less-garbled/175435>\
**Category:** Rails\
**Created:** [September 13, 2009, 10:57pm UTC](https://www.ruby-forum.com/t/proper-syntax-for-text-field-less-garbled/175435 "2009-09-13T22:57:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dudebot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Dudebot](https://www.ruby-forum.com/u/Dudebot)\
**Post date:** [September 13, 2009, 10:57pm UTC](https://www.ruby-forum.com/t/proper-syntax-for-text-field-less-garbled/175435/1 "2009-09-13T22:57:59Z")

</div>

I’m almost there… if someone could please help me 🙂

OK, if I have this in my .html.erb:

\<%= button\_to “Add to Cart” , :action =\> ‘add\_to\_cart’, :id =\>  
item, :amount =\> 3 %\>

I get proper behavior. But I’m trying to figure out how to wire up a  
text field for :amount

\<%= text\_field\_tag ‘$’, @amount %\>

  
\<%= button\_to “Add to Cart” , :action =\> ‘add\_to\_cart’, :id =\>  
item, :amount =\> @amount %\>

Doesn’t work. Does anybody have an idea of what would?

add\_to\_cart is now working with

def add\_to\_cart  
item = Item.find( params[:id] )  
@cart = find\_cart  
@cart.add\_item( item, params[:amount] )  
end

Can anyone help??

Many TIA,  
Craig

---

<div class="post-metadata">

**Author:** ![Dudebot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Dudebot](https://www.ruby-forum.com/u/Dudebot)\
**Post date:** [September 13, 2009, 11:48pm UTC](https://www.ruby-forum.com/t/proper-syntax-for-text-field-less-garbled/175435/2 "2009-09-13T23:48:54Z")

</div>

On Sep 13, 9:56 pm, Dudebot [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= text\_field\_tag ‘$’, @amount %\>
> 
>   
> \<%= button\_to “Add to Cart” , :action =\> ‘add\_to\_cart’, :id =\>  
> item, :amount =\> @amount %\>
> 
> Doesn’t work. Does anybody have an idea of what would?

You need a form. What button\_to does is create a form containing just  
a button, whereas you need a form containing both the textfield and  
the submit button

Fred
