jhund / filterrific

Filterrific is a Rails Engine plugin that makes it easy to filter, search, and sort your ActiveRecord lists.
http://filterrific.clearcove.ca
MIT License
910 stars 124 forks source link

Two filterrific selects with same scopes #99

Open MrBelousov opened 8 years ago

MrBelousov commented 8 years ago

Hello, I've created Form helper that helps me to add filters on page `class ActionView::Helpers::FormBuilder

def add_filter(option_name, id: '', include_blank: false)

  select(:with_any_product_option_values,

         ProductOption.includes(:option).where(options: {name: option_name}).pluck(:value).uniq,

         { include_blank: include_blank }, class: 'form-control', id: id)

end

end`

I'm using it like this: `<%= form_for_filterrific @filterrific do |f| %>

  <%= f.add_filter('Dial', include_blank: '- Any -') %>

  <%= f.add_filter('Color', id: '123', include_blank: '- Any -') %>

<% end %>`

Here is my scope: scope :with_any_product_option_values, proc { |option_value| includes(:options) .where(product_options: { value: option_value }) }

And here is my controller action: `def index @filterrific = initialize_filterrific( Product, params[:filterrific], select_options: { sorted_by: Product.options_for_sorted_by, with_name: Product.options_for_select, with_any_option_names: Product.options_for_select, with_any_product_option_values: Product.options_for_select } ) or return @products = @filterrific.find.page(params[:page])

respond_to do |format|
  format.html
  format.js
end

end`

But if I go this way, I got the same parameters in url, like: 'utf-8&filterrific[with_any_product_option_values]=Colored&filterrific[with_any_product_option_values]=Green'

And filterrific doesn't work because of this.. Is there any way to make custom name parameters in url for filterring?