在斯普雷的社团中搜索

问题描述 投票:1回答:1

Spree报表利用ransack进行搜索。根据ransack文档,我应该可以使用下面这行代码来搜索所有包含多个项目的订单。

Spree::Order.ransack(line_items_quantity_gt: 1)

但是当我在控制台中输入这行代码时,我得到了如下的输出结果。

Ransack::Search<class: Spree::Order, base: Grouping <combinator: and>>

根据ransack文档,应该可以。但在搜索参数中,这个关联似乎并不被接受。Line items在Spree::Order.ransackable_associations提供的列表中,所以我有点困惑,为什么这不工作。

ruby-on-rails spree ransack
1个回答
0
投票

一些关联(属性,作用域),我的是 白名单,其他的则被ransack忽略。

要覆盖应用中的默认值,需要在文件中添加(到) app/controllers/spree/products_controller_decorator.rb:

Spree::ProductsController.class_eval do

  Spree::Product.whitelisted_ransackable_associations = %w[taxons stores variants_including_master master variants]

end
© www.soinside.com 2019 - 2024. All rights reserved.