What’s the best way to include a LIKE clause in a Rails query i.e. something along the lines of (the completely incorrect):
Question.where(:content => 'LIKE %farming%')
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.
If this is Rails 3 you can use Arel’s
matches. This has the advantage of being database agnostic. For example:This is somewhat clunky, but easily extracted to scopes, e.g.:
Of course to join with “AND” you could just chain the scopes.
Edit: +1 to metawhere and squeel though (haven’t tried latter but it looks cool) They both add this type of functionality and much more.