'Combine search predicates in Ransack

How can I implement the equivalent of :name_eq_or_description_cont, which combines _eq and _cont predicates into the same search key, so that I can create a search field in the form as:

<%= search_field_tag :item, :name_eq_or_description_cont %>

?



Solution 1:[1]

I came across something like this, but it seems to need to be pre-configured on the back end. Not sure how I would pass Ransack::Constants::OR from the front end:

.ransack({title_cont: params[:q], id_eq: params[:q]}, { grouping: Ransack::Constants::OR })

Actually, update, this works:

Departure.order(search_order).limit(search_limit).ransack({m: 'or', name_cont: "20967", id_eq: "20967"}).result

Not sure what "m" is, but it seems to work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1