Reputation: 2141
I'm writing a simple search function that checks multiple fields of a record for likeness with the search parameter. It works when I just compare a single field:
key = params[:searchform][:keyword]
fkey = '%' + key + '%'
@games = Game.where('title LIKE ?', fkey).all
But I want to check other fields ('category' and 'rules' for example) for likeness also, and return records that match any of these fields. How can I do that?
Upvotes: 1
Views: 584
Reputation: 2820
Assuming that these fields belongs to the Game class, you should do something like:
rules = params[:searchform][:rules]
@games = Game.where('title LIKE ? and rules = ?', fkey, rules).all
And so on.
Upvotes: 3