Here's a post that describes it.
Basically you use a SQL LIKE expression to match strings that contain something. Using where("topic like ?", "%bla%") will do the trick.
However, the naive decision is susceptible to attacks due to lack of sanitation. If the user enters his own % wildcard character, he may receive data that you do not want to provide! The message above says that you manually sanitize these user inputs:
escaped_str = "bla".gsub ('%', '\%').gsub ('_', '\_') Topic.where("topic like ?", "%" + escaped_str + "%")
Pavel shved
source share