简体   繁体   中英

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

?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM