# Multiple classes on form text\_field

**URL:** <https://www.ruby-forum.com/t/multiple-classes-on-form-text-field/190144>\
**Category:** Rails\
**Created:** [June 17, 2010, 1:34am UTC](https://www.ruby-forum.com/t/multiple-classes-on-form-text-field/190144 "2010-06-17T01:34:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [June 17, 2010, 1:34am UTC](https://www.ruby-forum.com/t/multiple-classes-on-form-text-field/190144/1 "2010-06-17T01:34:29Z")

</div>

Consider :

* * *

\<% form\_for(@z) do |f| %\>  
\<%= f.error\_messages %\>

\<%= f.label :x %\>  
 \<%= f.text\_field :x, :class =\> 's' %\>

\<%= f.submit 'Update' %\>

\<% end %\>
* * *

The above form works fine. What I want to do is have two classes, s and  
t, associated with text\_field :x.

The following does not work.

* * *

\<% form\_for(@z) do |f| %\>  
\<%= f.error\_messages %\>

\<%= f.label :x %\>  
 \<%= f.text\_field :x, :class =\> {'s', 't'} %\>

\<%= f.submit 'Update' %\>

\<% end %\>
* * *

The code above will generate a single class class=“st”

How can I have two classes in the same field using form helper? Do I  
have to generate my own html?

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [June 17, 2010, 6:50am UTC](https://www.ruby-forum.com/t/multiple-classes-on-form-text-field/190144/2 "2010-06-17T06:50:28Z")

</div>

Hi Ralph,

Have you tried this:

\<%= f.text\_field :x, :class =\> ‘s t’ %\>

Regards,

Saurabh
