This gem adds the "cont_any_word" predicate to Ransack for filtering more natural and human.
User.ransack(email_cont_any_word: "@example.com test").result.to_sql #=> SELECT "users".* FROM "users" WHERE ("users"."email" LIKE '%@example.com%' AND "users"."email" LIKE '%test%')
It is also possible to search for whole sentences
User.ransack(encrypted_password_cont_any_word: '"yeah this is my password" password some').result.to_sql #=> SELECT "users".* FROM "users" WHERE ("users"."encrypted_password" LIKE '%yeah this is my password%' AND "users"."encrypted_password" LIKE '%password%' AND "users"."encrypted_password" LIKE '%some%')
Add this line to your application's Gemfile:
gem 'ransack_predicate_cont_any_word'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ransack_predicate_cont_any_word
Contribution directions go here.
The gem is available as open source under the terms of the MIT License.