views:

51

answers:

1

Is it possible to specify html attributes while using the form_for helper methods?

For example:

<% form_for @user do |f| %> 
   <%= f.label :username%>
   <%= f.text_field :username %>
   <%= f.submit "Signn Up" %>
<% end %>

How would I go about specifying the class for the label? Is it possible, or do I have to resort to label()?

+3  A: 

On mostly helpers, the last arg is a hash of html options for the element.

   <%= f.label :username, "Username", :class => "class" %>
Lucas
I had tried that, it just generates the following:<label for="user_username">classinlined</label>
Ryan
The updated answer throws an ArgumentError with the message: "wrong number of arguments (4 for 3)"That does work if I use just the label method instead of f.label... in which case the answer to my original question is "No, you cant use the f.label method"
Ryan
Sorry for the mistakes, was taking the docs from FormHelper instead of FormBuilder class.
Lucas