I needed code where there would be a dynamic number of terms to search a single field. Here’s the code I used.
StackOverflow pages (didn’t work for me):
- Question about queries with multiple where clauses, Rails 3
- How to specify multiple values in where with AR query interface in rails3
Non-StackOverflow (didn’t work for me, but still helpful)
def self.search_by_location(terms) terms = terms.split(',') where(('facilities.name=? ' * terms.count).split(' ').join(' OR '), *terms) end