I am trying to filter by multiple fields. The fields are taken from an ENUM list and put in checkbox fields, then saved into an array. The GET request for what I'm trying to filter looks like this: {"statuses" => ["active", "past_due"]}. I have a scope with the query, which should filter by the values selected. I am assuming the problem is in the model.
The model:
scope :subscription_status, -> (statuses) {where :subscription_status => statuses}
The controller:
@users = User.where(nil)
@users = @users.subscription_status(params[:statuses]) if params[:statuses].present?
The view (html.haml):
= form_tag root_path, :method => 'get' do
- @subscription_statuses.each do |status|
= check_box_tag 'statuses[]', status
= status
= submit_tag "Filter", :name => nil
@subscription_statuses contains the ENUM list.
My other filters work on the same principle, but this one doesn't seem to work. The page reloads, the GET params are sent, but there is no filtering.
Thank you in advance. :)
EDIT:
@subscription_statuses = User.subscription_statuses.keys
This is an array of strings, and the values in the database are saved as strings.