Ruby on rails 4 using filterrific to filter based on checkbox -
i using filterrific gem in rails app filter result, have events filtered based on options code follows
event.rb
filterrific :default_filter_params => { :sorted_by => 'created_at_desc' }, :available_filters => %w[ sorted_by search_query with_category_id with_area ] # default will_paginate self.per_page = 9 scope :with_category_id, lambda { |category_ids| where(category_id: [*category_ids]) }
events_controller.rb
def index @filterrific = initialize_filterrific( event, params[:filterrific], :select_options => { sorted_by: event.options_for_sorted_by, with_category_id: category.options_for_select } ) or return @events = @filterrific.find.paginate(page: params[:page], per_page: 6).where(is_job: false) respond_to |format| format.html format.js end end
index.html.erb
<%= form_for_filterrific @filterrific, :class => 'col s12' |f| %> <%= render_filterrific_spinner %> <%= f.hidden_field :source , :value => 'event' %> <div class="col s12 m3 "> <div class="filter-container"> <li> <%= f.select( :with_category_id, @filterrific.select_options[:with_category_id], { include_blank: ' ' }, class: 'select-filter' ) %> <label>select category</label> </li> </div> <%= link_to( 'reset filters', reset_filterrific_url, ) %> </div> <% end %> <%= render( partial: 'events/list', ) %>
index.js.erb
<% js = escape_javascript( render(partial: 'events/list') ) %> $("#filterrific_results").html("<%= js %>"); $('#filterrific_results').load(document.url + ' #filterrific_results');
_list.html.erb
<div id="filterrific_results"> <% @events.each |event| %> <%= link_to event.name, company_event_path(event.company.id, event.id) %> <% end %> </div>
so doing here filtered events based on category select box want add feature in select box select box must contain checkbox elements can filter multiple category result, when check on 1 category filter result single category , when click category filter result category , previous category checked
would great fix , thankx in advance
you can use multiple: true
, this:
<%= f.select( :with_category_id, @filterrific.select_options[:with_category_id], { include_blank: ' ' }, { multiple: true, class: 'select-filter'} ) %>
Comments
Post a Comment