简体   繁体   中英

Filterrific Not Passing Multiple Parameters to Scope

I have a filterrific scope that accepts multiple parameters. The scope appears to be functioning correctly (I can call Marketplace::Lot.with_price({}) in the console and it returns the correct results), but filterrific isn't passing any data to it when I enter information on the form.

Here is my filterrific declaration in the model

  filterrific(
    default_filter_params: { sorted_by: 'time_remaining_asc' },
    available_filters: [
      :with_price,
      :sorted_by,
      :lots_with_item_type,
      :search_query
    ]
  )

Here is what my controller looks like:

@filterrific = initialize_filterrific(
  Marketplace::Lot,
  params[:filterrific],
  select_options: {
    sorted_by: Marketplace::Lot.options_for_sorted_by,
    item_types: Marketplace::Lot.options_for_item_types
  },
  persistence_id: 'marketplace_key',
) or return

@lots = @filterrific.find.paginate(page: params[:page], per_page: 20)

and my view

    <%= f.fields_for :with_price,  OpenStruct.new(@filterrific.with_price) do |with_price_fields| %>
    <div class="marketseach__shards shards">
      <%= with_price_fields.text_field :shards_min, class: 'marketplace__value input', placeholder: 'Low Value' %>
      -
      <%= with_price_fields.text_field :shards_max, class: 'marketplace__value input', placeholder: 'High Value' %>
    </div>
    <span class="marketsearch__text">or</span>
    <div class="marketsearch__gems gems">
      <%= with_price_fields.text_field :gems_min, class: 'marketplace__value input', placeholder: 'Low Value' %>
      -
      <%= with_price_fields.text_field :gems_max, class: 'marketplace__value input', placeholder: 'High Value' %>
    </div>
    <% end %>

When I submit the form, the price fields appear in the params hash

"filterrific"=>
 { "search_query"=>"Programming",
   "lots_with_item_type"=>"",
   "with_price"=>{"shards_min"=>"200", "shards_max"=>"", "gems_min"=>"", "gems_max"=>""},
   "sorted_by"=>"alpha_asc"
 },

However, it never gets to the scope (I have a binding.pry in the scope that never gets hit). I should note that all other scopes are working correctly.

I'm sure I'm missing something obvious but I can't find it for the life of me.

There is a bug in Filterrific that gives an error when multiple fields are passed in a scope. Currently fixed in Pull request #116 however it has not been merged into the master branch as of this post on 12/24/2016... If you manually update the filterrific gem it will work until the new release is posted...

https://github.com/jhund/filterrific/pull/116

John

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM