Given a delimited string of unknown length e.g. 'peanut,banana'
or 'bacon,eggs,toast,arugula'
, I want to use named_scope or searchlogic in my rails 2.3.9 app to end up with a SQL statement like SELECT * FROM foods WHERE (name LIKE 'peanut') OR (name LIKE 'banana')
. Ideas?
Asked
Active
Viewed 227 times
0

Zeke
- 1,448
- 14
- 30
1 Answers
1
Food.name_like_any("peanut", "banana")
# it also accepts an array
Food.name_like_any(["bacon", "eggs", "toast", "arugula"])
from the searchlogic readme

Chap
- 3,483
- 1
- 24
- 27
-
To turn a CSV string into an array you'd do `"foo,bar,zomg".split(',')` This plus the above is what you neeed. – jonnii Dec 02 '10 at 14:51