Hello,
I'm attempting to create a filter on a rails application that uses multiple check boxes corresponding to one db-column/attribute to filter through results, but I'm not sure how to go about it exactly.
EX.
index shows a list of the last few years' weather and you want to filter through it
These attributes would be part of a Day class.
View
<fieldset>
`
<legend>Sky</legend>
<%= check_box_tag('filter[sky][]', 'sunny') %>Sunny
<%= check_box_tag('filter[sky][]', 'partly sunny') %>Partly Sunny
<%= check_box_tag('filter[sky][]', 'overcast') %>Overcast
</fieldset>
<fieldset>
<legend>Humidity</legend>
<%= check_box_tag('filter[humidity][]', 'low') %>Low
<%= check_box_tag('filter[humidity][]', 'average') %>Average
<%= check_box_tag('filter[humidity][]', 'high') %>High
</fieldset>
I want to then be able to go through the options for each filter and apply all that have been selected. So if I want to see all days that were sunny with low and average humidity, I would check those boxes and get days that were summy with either low humidity or average humidity. SQL wise we'd be talking an IN clause.
I'm pretty new to rails so I'm not sure if there's some special rails functionality I should use for this or not. Do I just need to write a function to run through the check boxes and build the SQL statement?
Any help is greatly appreciated. I will edit this post if I need to in order to clarify anything.