[英]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. 范围似乎运行正常(我可以在控制台中调用Marketplace :: Lot.with_price({}),并且它返回正确的结果),但是当我在表单上输入信息时,filterrific不会将任何数据传递给它。
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 当我提交表单时,价格字段显示在params哈希中
"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). 但是,它永远不会到达作用域(我在作用域中有一个binding.pry从未被击中)。 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. Filterrific中有一个错误,当在范围中传递多个字段时会出错。 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... 目前已在Pull request#116中修复,但是截至2016年12月24日,该请求尚未合并到master分支中。如果您手动更新filterrific gem,它将在发布新版本之前起作用...
https://github.com/jhund/filterrific/pull/116 https://github.com/jhund/filterrific/pull/116
John 约翰
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.