简体   繁体   中英

Ruby on Rails: Replacing the “LIKE” part of the SQL query with Ruby code

In my application I have a "LIKE" SQL query that is something like...

Item.where("name LIKE ?", "%"+params[:q]+"%").all

But I want to hit the db only 1x (at application start-up), since the number of Items is huge, and load this generic part...

Item.all

...into memory (a global variable), so I can later reuse its content throughout the app, in different cases, and refined with some case-specific Ruby code (see the "LIKE" part).

What's the speediest way to do such "filtering" with Ruby?

您可以为此使用低级缓存吗?

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