如何将此form_tag助手转换为simple_form_for调用?

时间:2014-10-04 18:14:30

标签: ruby-on-rails css3 ruby-on-rails-4 twitter-bootstrap-3 simple-form

这是我想要制作的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 -->

这就是这个:

Broken Search Form

而我想要实现的目标是:

Desired Search Form

由此产生:

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 %>

2 个答案:

答案 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