有这样的表格
<%= form_tag 'search', method: 'get', class: 'form-horizontal' do %>
<%= label_tag :search, 'Enter url here' %>
<%= text_field_tag :search %>
<%= submit_tag 'Get it!' %>
<% end %>
上面的代码为class='form-horizontal'
代码添加form
。
如何为每个输入字段添加class='form-control'
?
答案 0 :(得分:3)
试试这个:
text_field_tag :search, nil, class: 'form-control'
供将来参考:
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" />
答案 1 :(得分:0)
<%= 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 %>