Rails - forms

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

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
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.

On 8/3/06, Dark A. [email protected] 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.

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)
JvYAML, RbYAML, JRuby and Jatha contributor
System Developer, Karolinska Institutet (http://www.ki.se)
OLogix Consulting (http://www.ologix.com)

“Yields falsehood when quined” yields falsehood when quined.

On 8/3/06, Greg D. [email protected] 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/


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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs