9

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 %>

?

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.