[英]How to search for a substring in a custom filter in ActiveAdmin?
In the past: 以往:
A model User
has a string filed first_name
. 模型
User
的字符串为first_name
。 If I write filter :first_name
in ActiveAdmin model it would display a drop-down besides the input field with the options Contains
, Equals
, Starts with
, Ends with
. 如果我在ActiveAdmin模型中编写
filter :first_name
,它将在输入字段旁边显示一个下拉列表,其中Contains
选项Contains
, Equals
, Starts with
, Ends with
。 So for examle if I choose Contains
and write ik
, it would find, for example Mike. 因此,例如,如果我选择
Contains
并编写ik
,它将找到,例如Mike。
Now: 现在:
If I use a custom filter I just get a large input, spanning across two columns, which only does exact search. 如果使用自定义过滤器,我将得到一个很大的输入,跨越两列,仅进行精确搜索。 I define my filter like so:
我这样定义过滤器:
ransackable_scopes
. ransackable_scopes
将其列入白名单。 filter :my_filter, as: :string
. filter :my_filter, as: :string
。 How do I get the functionality to seach for substrings? 如何获取功能来查找子字符串?
To search for substrings you must use the Ransack Search Predicate Syntax ie if you want search a substring on field first_name
you must configure this way: 要搜索子字符串,您必须使用Ransack搜索谓词语法,即,如果要在字段
first_name
上搜索子字符串,则必须采用以下方式进行配置:
filter :first_name_cont, as: :string, label: "Name"
You can find more information here 您可以在这里找到更多信息
I hope it helps. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.