Ransack searches for every word in the text box

I will search with ransack in my Rails application for users by first and last name. In one text field for firstname and in one text field for lastname, the application user must be able to search for several parts of the name.

eg. the user will log in to Thomas Jeffrey, and this should result in:

SELECT FROM users WHERE firstname LIKE "%Thomas%" AND firstname LIKE "%Jeffrey%"; 

If I use firstname_cont, the result looks like this:

 SELECT FROM users WHERE firstname LIKE "%Thomas Jeffrey%"; 

When I tried firstname_cont_all, I had something else.

Thanks for any hint.

+4
source share
1 answer
 User.search(firstname_cont_all: params[:my_field].split) 

However, I do not know how to correctly enter array partitioning when using the builder condition_field utility.

+1
source

Source: https://habr.com/ru/post/1445618/


All Articles