I’m trying to build a miniature engine that will allow a search query to be built up on the fly by user input. I get the column name and the search string in the params, let’s assume:
params = {:filter_column => "column_name", :filter_string => "search term"}
I know that if I were just calling a standard sort of where on my model it would be along the lines of:
ModelName.where("column_name LIKE ?", params[:filter_string])
The problem I have is I’m trying to compile a list of my filters and then apply them one at a time to the search. Can I build up the where string before I call the where method?
I’ve tried:
ModelName.where("? LIKE ? ", column_name, search_term)
without much luck. Any hints, tips or pointers?
thanks!
You might want to try a solution that uses the Metawhere Gem
i’m thinking something like:
and you can build each one sequentially in it’s own condition separated by commas or subsequent calls to where.