繁体   English   中英

过滤不将多个参数传递到范围

[英]Filterrific Not Passing Multiple Parameters to Scope

我有一个过滤范围,可以接受多个参数。 范围似乎运行正常(我可以在控制台中调用Marketplace :: Lot.with_price({}),并且它返回正确的结果),但是当我在表单上输入信息时,filterrific不会将任何数据传递给它。

这是我在模型中的过滤性声明

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

这是我的控制器的外观:

@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)

和我的看法

    <%= 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 %>

当我提交表单时,价格字段显示在params哈希中

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

但是,它永远不会到达作用域(我在作用域中有一个binding.pry从未被击中)。 我应该注意,所有其他范围都在正常工作。

我确定我缺少明显的东西,但终生找不到。

Filterrific中有一个错误,当在范围中传递多个字段时会出错。 目前已在Pull request#116中修复,但是截至2016年12月24日,该请求尚未合并到master分支中。如果您手动更新filterrific gem,它将在发布新版本之前起作用...

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

约翰

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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