简体   繁体   中英

How to search for the exact word in the parentheses using rails?

I want to know how to find the exact word in the parenthesis and not words that include the word that has been searched. For example, if I trying to search for Carbon Monoxide [CO] and if I searched CO I want my results to only show Carbon Monoxide [CO] and not like Carbon Dioxide [CO2] .

So far I have,

where("lower(gas_analyte) LIKE lower(?)", "%#{gas_analyte}%")

Don't use like query in this case!.You can use where condition which is the result of filtering the current relation according to the conditions in the arguments. it will return exact params matching records..

where(gas_analyte:gas_analyte)

Ilike it returns something matching records of ur params..

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