2

Having such form

<%= form_tag 'search', method: 'get', class: 'form-horizontal' do %>
     <%= label_tag  :search, 'Enter url here' %>
     <%= text_field_tag :search  %>
     <%= submit_tag 'Get it!' %>
    <% end %>

Code above adds class='form-horizontal' for form tag.

How can I add class='form-control' for each input field ?

2 Answers 2

5

Try this:

text_field_tag :search, nil, class: 'form-control'

For future reference:

text_field_tag(name, value = nil, options = {})

text_field_tag :search
# => <input id="search" name="search" type="text" />

text_field_tag :search, 'Enter your search query here'
# => <input id="search" name="search" type="text" value="Enter your search query here" />

text_field_tag :search, nil, class: 'form-control'
# => <input class="form-control" id="search" name="search" type="text" />
Sign up to request clarification or add additional context in comments.

Comments

2
<%= form_tag 'search', method: 'get', class: 'form-horizontal' do %>
   <%= label_tag  :search, 'Enter url here' %>
   <%= text_field_tag :search, {:class => 'form-control'}  %>
   <%= submit_tag 'Get it!' %>
<% end %>

Comments

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.