Simple ActiveRecord filtering in controller
In the article Search and Filter Rails Models Without Bloating Your Controller, the author described a way to filter records by multiple params:
params.slice(:status, :location, :starts_with).each do |key, value|
@products = @products.public_send(key, value) if value.present?
end
As an alternative, you can write:
YourModel.where(params.slice(*[your_filtering_params_array]))
This is for a newer Rails version.