Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filterrific Not Passing Multiple Parameters to Scope #114

Closed
ryanh opened this issue Nov 21, 2016 · 3 comments
Closed

Filterrific Not Passing Multiple Parameters to Scope #114

ryanh opened this issue Nov 21, 2016 · 3 comments

Comments

@ryanh
Copy link

ryanh commented Nov 21, 2016

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.

@3buson
Copy link

3buson commented Nov 23, 2016

I seem to be having the same problem, are we missing something? 🤔
I've seen that the log contains 'Unpermitted parameter' which is the one that is causing problems but I'm not sure why this only happens with multiple parameters...

@ayaman
Copy link
Contributor

ayaman commented Nov 24, 2016

Having the same problem here as well. I did some digging in the code and it seems that the issue is happening because Filterrific uses the permit method of ActionController::Parameters (http://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-permit) to decide which filters are valid and which aren't, and this method expects nested params to be passed as a hash in order to permit them.

@edwardmp
Copy link
Contributor

edwardmp commented Dec 10, 2016

Fixed in #115 by @ayaman and me. @jhund can you please merge this in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants