I have a Meetings class which contains a 'days' attribute, which I've serialized into an Array. The method I used to store an array is described here:
Link- Array Attribute for Ruby Model
So for example, running:
Meeting.first.days
might return:
["Monday", "Tuesday", "Wednesday"]
Here's an example of an entire Meeting object:
#<Meeting id: 7, address: "10 Canal Street", neighborhood: "Tribeca", building_name: "Yale Club", name: "Alumni Luncheon", start_time: "00:00", end_time: "00:35", notes: "", days: ["Tuesday", "Wednesday", "Thursday"], zip_code: 10055, special_interest: nil, meeting_type: nil, area: "Manhattan", latitude: 40.8104529, longitude: -73.9922805, created_at: "2013-09-29 22:02:29", updated_at: "2013-09-29 22:02:29">
I have a search form with checkboxes corresponding to the days of the week, so users can check which days they want to search for a meeting. For instance, a user might want to see any meetings whose days include Monday.
My expectation is for the search to return any Meeting object with "Monday" included in its 'days' array. But I'm having trouble using ActiveRecord to filter these meetings. So far I have:
meetings = Meeting.order(:start_time)
meetings = meetings.where("days in (?)", days_params)
But this keeps filtering the 'meetings' variable down to 0 results. I could be wrong but I think the problem is that this only works if 'days' is not an array, i.e. if I compare a string with an array then it might work. Since I need to compare the union of two arrays, anyone have an idea?