Currently I have a registration form that is built like this: <label for="First name">First name</label> <%= text_field "user", "first_name" %><br> <label for="Last name">Last name</label> <%= text_field "user", "last_name" %><br> <label for="Email">Email</label> <%= text_field "user", "email" %><br> <label for="User Type">User type</label> <%= text_field "user", "type" %><br> <label for="Password">Password</label> <%= text_field "user", "password" %><br> <p><input type="Submit" value="Register"/></p> 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: ? <label for="name">Name</label> <input id="name" name="name"><br> 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 Ambient <sambient@gmail.com> 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. -- Greg Donald http://destiney.com/
Dark Ambient wrote:> Currently I have a registration form that is built like this: > > <label for="First name">First name</label> > <%= text_field "user", "first_name" %><br> > <label for="Last name">Last name</label> > <%= text_field "user", "last_name" %><br> > <label for="Email">Email</label> > <%= text_field "user", "email" %><br> > <label for="User Type">User type</label> > <%= text_field "user", "type" %><br> > <label for="Password">Password</label> > <%= text_field "user", "password" %><br> > <p><input type="Submit" value="Register"/></p> > > 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: ? > <label for="name">Name</label> > <input id="name" name="name"><br>I''m not sure if I understand what you want. If you do <%= text_field :user, :first_name %> this will generate <input id="user_first_name" name="user[first_name]" size="30" type="text" /> I recommend you create a helper like this: def labeled_text_field(name, obj, meth, options ={}) "<label for=\"#{obj}_#{meth}\">#{name}</label>" + text_field obj, meth, options end and your example can be written like this: <%= labeled_text_field "First name", :user, :first_name %><br/> <%= labeled_text_field "Last name", :user, :last_name %><br/> <%= labeled_text_field "Email", :user, :email %><br/> <%= labeled_text_field "User type", :user, :type %><br/> <!-- shouldn''t be text_field, should be password_field --> <%= labeled_text_field "Password", :user, :password %><br/> -- Ola Bini (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, Ola Bini <ola.bini@ki.se> wrote:> I''m not sure if I understand what you want.Learn how to style the form tags in Rails.> I recommend you create a helper like this: > def labeled_text_field(name, obj, meth, options ={}) > "<label for=\"#{obj}_#{meth}\">#{name}</label>" + > text_field obj, meth, options > endI''m probably going to need and read through the material on formhelpers. Right now "text_field obj, meth, options" is throwing an error which I''m assuming is becaue I haven''t defined an obj, method or options. Stuart
On 8/3/06, Greg Donald <gdonald@gmail.com> wrote:> It''s also worth mentioning that a style like: > > input{ font-family: sans-serif; } > > will style all your input fields. > -- > Greg Donald > http://destiney.com/ > _______________________________________________Using input doesn''t seem to work. For instance this is one field: <%= text_field "user", "first_name", "size" => 15 %><br> 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