I have an ActiveRecord object RaceCarDriver. Three of the fields are boolean: is_from_texas, is_from_arkansas, and is_from_indiana. In the user search interface, the user could select neither to see all results, select is_from_texas to see only drivers from Texas, or select is_from_texas and is_from_indiana to see all drivers from one of those states.
Now, I know this example is a bit contrived, but I wanted to avoid the complexity of the actual app.
My best attempt is along these lines:
@drivers = RaceCarDriver.select('name').
where(params[:check_texas] == 0 || :is_from_texas => params[:check_texas]).
where(params[:check_arkansas] == 0 || :is_from_arkansas => params[:check_arkansas]).
where(params[:check_indiana] == 0 || :is_from_indiana => params[:check_indiana])
However, this ANDS the chained where clauses together, making it so that if Texas and Indiana were both checked a driver would have to be from both states.
Again, I know this is contrived. Any help is appreciated.
EDIT
Solution 1:
Solution 2: