0
我使用filterrific寶石在我的Rails應用程序來篩選結果,我有一個基於選項 我的代碼將被過濾的事件如下的Ruby on使用filterrific軌道4過濾器的基礎上覆選框
event.rb
filterrific :default_filter_params => { :sorted_by => 'created_at_desc' },
:available_filters => %w[
sorted_by
search_query
with_category_id
with_area
]
# default for 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 do |format|
format.html
format.js
end
end
index.html.erb
<%= form_for_filterrific @filterrific, :class => 'col s12' do |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: ' Any ' },
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 do |event| %>
<%= link_to event.name, company_event_path(event.company.id, event.id) %>
<% end %>
</div>
所以我在做什麼這裏是我過濾了事件b選擇框 ,但現在我想在選擇框中添加該功能,選擇框必須包含複選框元素,以便我可以篩選多個類別結果,以便當我檢查一個類別時,它將過濾由單一的類別,當我點擊另一個類別,將過濾與該類別和以前的分類結果,結果被查
將是一個很大的幫助,以解決這個問題,Thankx提前