Ransack搜索工作正常,有一些属性:
Spree::Callback.all.ransack(name_cont: 1).result
SELECT "spree_callbacks".* FROM "spree_callbacks" WHERE ("spree_callbacks"."name" ILIKE '%1%')
不要与他人合作......
Spree::Callback.all.ransack(phone_cont: 1).result
SELECT "spree_callbacks".* FROM "spree_callbacks"
出了什么问题?
P.S。回调是我在Spree模块下的自定义模型
Callback对象的例子:
Spree::Callback.first
Spree::Callback Load (1.4ms) SELECT "spree_callbacks".* FROM "spree_callbacks" ORDER BY "spree_callbacks"."id" ASC LIMIT 1
=> #<Spree::Callback:0x00000009eb68c0 id: 39,
phone: "123",
comment: "",
created_at: Wed, 12 Jul 2017 03:37:03 UTC +00:00,
updated_at: Wed, 12 Jul 2017 03:41:34 UTC +00:00,
name: "123",
processed: true>
答案 0 :(得分:3)
@ nuT707 - 为了能够使用ransack gem进行搜索,您首先必须将所有要执行搜索的字段列入白名单。
所以在callback.rb
模型中添加以下行 -
self.whitelisted_ransackable_attributes |= %w[phone]
现在尝试用搜索搜索。
希望这会对你有所帮助。