这是我想要制作的HTML:
<div class="col-lg-3">
<div class="input-group custom-search-form">
<input type="text" class="form-control">
<span class="input-group-btn">
<button class="btn btn-default" type="button">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div><!-- /input-group -->
</div>
这是我的vanilla Rails表单助手:
<div class="col-lg-3">
<div class="input-group custom-search-form">
<%= form_tag(dashboard_index_path, :method => "get", id: "search-form", :class => "navbar-form navbar-left") do %>
<%= text_field_tag :search, params[:search], placeholder: "Search videos", :class => "form-control" %>
<span class="input-group-btn">
<%= submit_tag "", name: nil, class: "btn btn-default" %>
<span class="glyphicon glyphicon-search"></span>
</span>
<% end %>
</div><!-- /input-group -->
</div> <!-- //col-lg-3 -->
这就是这个:
而我想要实现的目标是:
由此产生:
http://bootsnipp.com/snippets/featured/search-box
我想使用simple_form_for
生成上述HTML,而不是form_tag
帮助器。
所以我安装了simple_form
。如何将此form_tag
转换为simple_form_for
来电?
<%= form_tag(dashboard_index_path, :method => "get", id: "search-form", :class => "navbar-form navbar-left") do %>
答案 0 :(得分:1)
您也可以使用form_tag
执行此操作。请尝试以下代码:
<%= form_tag(dashboard_index_path, :method => "get", id: "search-form", :class => "navbar-form navbar-left") do %>
<div class="col-lg-3">
<div class="input-group custom-search-form">
<%= text_field_tag :search, params[:search], placeholder: "Search videos", :class => "form-control" %>
<span class="input-group-btn">
<%= button_tag "", name: nil, class: "btn btn-default", type: "button" do %>
<span class="glyphicon glyphicon-search"></span>
<% end %>
</span>
</div><!-- /input-group -->
</div> <!-- //col-lg-3 -->
<% end %>
答案 1 :(得分:0)
Form_tag不生成输入html类和submit_tag也不生成按钮html类,也许css代码期望这个类,尝试使用button_tag