Combine search predicates in Ransack
Asked Answered
F

1

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

?

Fatshan answered 12/1, 2015 at 19:16 Comment(0)
S
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.

Sardella answered 23/5, 2022 at 17:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.