As we know
Things.where(“topic = ?”,”blah”)
searches for topics that match “blah”
However, what if I want to search for topics that contain “bla”
How should I do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here’s a post that describes it.
Basically, you use SQL
LIKEexpression to match strings that contain something. Usingwhere("topic like ?", "%bla%")would do the trick.However, naive solution is prone to attacks due to lack of sanitizing. If user types its own
%wildcard character, he can get data you don’t mean to provide! The post above suggests that you manually sanitize such user inputs: