Amar Desai
Amar Desai

Reputation: 77

Using ransack for Rails application material dropdown select in view

Just need to know how you add ransack code in rails view as I m taking array list as category items and passing into the bootstrap material

the code for rails

on top of starting line search path code

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

dropdown code dropdown without ransack which gives output with correct dropdown list

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

I m trying to add ransack this does not display my list

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

Upvotes: 0

Views: 658

Answers (1)

widjajayd
widjajayd

Reputation: 6263

you can do with list like this below,
in case you allow blank option you should add include_blank: true as sample below

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

Upvotes: 3

Related Questions