Search code examples
ruby-on-railsransack

ransack exact match of keyword search


how to use ransack gem in rails for exact match of search keyword instead of partial search?

for example -

If I search for keyword "formers", it should not search for "Transformers" etc, instead serach for only "formers".


Solution

  • Use the eq predicate: https://github.com/activerecord-hackery/ransack/wiki/Basic-Searching#eq-equals

    i.e. If you're searching the first_name field, then your form field would be first_name_eq