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()?

1 Answer 1

4

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

   <%= f.label :username, "Username", :class => "class" %>
Sign up to request clarification or add additional context in comments.

3 Comments

I had tried that, it just generates the following: <label for="user_username">classinlined</label>
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"
Sorry for the mistakes, was taking the docs from FormHelper instead of FormBuilder class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.