# Rails - forms

**URL:** <https://www.ruby-forum.com/t/rails-forms/101219>\
**Category:** Rails\
**Created:** [August 3, 2006, 5:01pm UTC](https://www.ruby-forum.com/t/rails-forms/101219 "2006-08-03T17:01:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [August 3, 2006, 5:01pm UTC](https://www.ruby-forum.com/t/rails-forms/101219/1 "2006-08-03T17:01:19Z")

</div>

Currently I have a registration form that is built like this:

First name  
\<%= text\_field “user”, “first\_name” %\>  
  
Last name  
\<%= text\_field “user”, “last\_name” %\>  
  
Email  
\<%= text\_field “user”, “email” %\>  
  
User type  
\<%= text\_field “user”, “type” %\>  
  
Password  
\<%= text\_field “user”, “password” %\>

My question is can I create a style named “text\_field”, it didn’t seem  
to work for me.  
In other words what would be the best way to style the input boxes. I  
guess it seems at this point text\_field is a proprietary to rails ?

Or can I do something like this: ?  
Name

TIA  
Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [August 3, 2006, 5:19pm UTC](https://www.ruby-forum.com/t/rails-forms/101219/2 "2006-08-03T17:19:20Z")

</div>

> My question is can I create a style named “text\_field”, it didn’t seem  
> to work for me.  
> In other words what would be the best way to style the input boxes.

I think you mean you want to create a class called text\_field, so you  
can use CSS to style your boxes, correct?

If you check the text\_field from the API docs:  
[http://rubyonrails.org/api/classes/ActionView/Helpers/FormHelper.html#M0](http://rubyonrails.org/api/classes/ActionView/Helpers/FormHelper.html#M0)  
00389

You can add additional options which show up as attributes. So you would  
do this:

\<%= text\_field “user”, “first\_name”, “class” =\> “text\_field” %\>

And then in your CSS you would have

input.text\_field { border: 1px solid black }

Or whatever.

- Mark.

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [August 3, 2006, 5:19pm UTC](https://www.ruby-forum.com/t/rails-forms/101219/3 "2006-08-03T17:19:21Z")

</div>

On 8/3/06, Dark A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> My question is can I create a style named “text\_field”, it didn’t seem  
> to work for me.

The api definition for text\_field is:

text\_field(object\_name, method, options = {})

The options hash at the end is where you would send your style class  
name. Something like this:

text\_field( ‘foo’, ‘bar’, { :class =\> ‘text\_field’ } )

It’s also worth mentioning that a style like:

input{ font-family: sans-serif; }

will style all your input fields. Or you might want

input.text\_field{ font-family: sans-serif; }

for specific input fields.

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [August 3, 2006, 5:43pm UTC](https://www.ruby-forum.com/t/rails-forms/101219/4 "2006-08-03T17:43:25Z")

</div>

Dark A. wrote:

> Password  
>   
>   
> I’m not sure if I understand what you want. If you do  
> \<%= text\_field :user, :first\_name %\>  
> this will generate

I recommend you create a helper like this:  
def labeled\_text\_field(name, obj, meth, options ={})  
“\<label for="#{obj}\_#{meth}"\>#{name}” +  
text\_field obj, meth, options  
end

and your example can be written like this:  
\<%= labeled\_text\_field “First name”, :user, :first\_name %\>  
  
\<%= labeled\_text\_field “Last name”, :user, :last\_name %\>  
  
\<%= labeled\_text\_field “Email”, :user, :email %\>  
  
\<%= labeled\_text\_field “User type”, :user, :type %\>

\<%= labeled\_text\_field “Password”, :user, :password %\>

–  
Ola B. ([http://ola-bini.blogspot.com](http://ola-bini.blogspot.com))  
JvYAML, RbYAML, JRuby and Jatha contributor  
System Developer, Karolinska Institutet ([http://www.ki.se](http://www.ki.se))  
OLogix Consulting ([http://www.ologix.com](http://www.ologix.com))

“Yields falsehood when quined” yields falsehood when quined.

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [August 6, 2006, 6:17pm UTC](https://www.ruby-forum.com/t/rails-forms/101219/5 "2006-08-06T18:17:05Z")

</div>

On 8/3/06, Greg D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> It’s also worth mentioning that a style like:
> 
> input{ font-family: sans-serif; }
> 
> ## will style all your input fields.
> 
> Greg D.  
> [http://destiney.com/](http://destiney.com/)
> 
> * * *

Using input doesn’t seem to work.  
For instance this is one field:  
\<%= text\_field “user”, “first\_name”, “size” =\> 15 %\>

Then in the corresponding style sheet I have:  
input {  
background: #0066FF;  
margin-left: 5%;  
margin-top: 2px;  
}  
input:hover {  
background: #FFFFFF;  
}

Any idea what I’m doing wrong ?

TIA  
Stuart
