[英]ransack searching each word in a text_field
I will searching with ransack in my Rails application for users by firstname and lastname. 我将使用我的Rails应用程序中的ransack搜索姓氏和名字的用户。 In one text_field for firstname and one text_field for lastname the application user should have the possibility to search for several parts of the name. 在一个用于名字的text_field和一个用于姓氏的text_field中,应用程序用户应该可以搜索名字的多个部分。
Eg the user will enter "Thomas Jeffrey" and this should results in: 例如,用户将输入“ Thomas Jeffrey”,这将导致:
SELECT FROM users WHERE firstname LIKE "%Thomas%" AND firstname LIKE "%Jeffrey%";
If I use firstname_cont the result looks like: 如果我使用firstname_cont,结果将如下所示:
SELECT FROM users WHERE firstname LIKE "%Thomas Jeffrey%";
When I was trying firstname_cont_all out, I got something different. 当我尝试firstname_cont_all时,我得到了一些不同的东西。
Thank you for any hint. 谢谢您的提示。
User.search(firstname_cont_all: params[:my_field].split)
但是,我不知道在使用ransack的condition_field
表单构建器实用程序时如何正确地将拆分引入数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.