在视图中使用ransack for Rails应用程序材料下拉列表

时间:2019-01-19 14:41:30

标签: ruby-on-rails ruby-on-rails-5 ransack

当我将数组列表作为类别项并传递到引导程序材料中时,只需知道如何在rails视图中添加ransack代码

导轨代码

在起始行搜索路径代码之上

 <%= search_form_for @search, url: events_path do |f| %>

下拉列表代码下拉列表(不带acksack),可提供带有正确下拉列表的输出

<div class="col">
     <div class="dropdown" id="dropdown">
      <p class="selected" id="selected"><span>Filter By Category1</span> <i class="material-icons">keyboard_arrow_down</i></p>

      <ul class="dropdown-list" id="dropdown-list">
         <a href="/events"> 
          <li>All Events </li>
          <% @category_list.each do |cat| %>
          <li class="selected" id="list"> <%= cat.name %></li>
          <% end %>
      </ul>
   </div>
 </div>

我正在尝试添加ransack,这不会显示我的列表

<div class="col">
     <div class="dropdown" id="dropdown">
      <%= f.select :category_name_eq, class: "selected" %>

      <ul class="dropdown-list" id="dropdown-list">
         <a href="/events"> 
          <li>All Events </li>
          <% @category_list.each do |cat| %>
          <li class="selected" id="list"> <%= cat.name %></li>
          <% end %>
      </ul>
   </div>
 </div>

1 个答案:

答案 0 :(得分:1)

您可以使用下面的列表,
如果允许空白选项,则应添加include_blank:true作为下面的示例

<div class="row form-group">
  <%= f.label "Filter By Category1 <i class="mi md-18">arrow_downward</i>".html_safe, :class => 'col-form-label col-sm-3' %>
  <div class="col-sm-9">
    <%= f.select :category_name_eq, 
      @category_list.all.map { |cat| [cat.name, cat.name] },
      { include_blank: true }, { class: 'form-control' } %>
  </div>
</div>