Skip to content

Instantly share code, notes, and snippets.

@noahhendrix
Last active September 4, 2015 20:24
Show Gist options
  • Save noahhendrix/9119825 to your computer and use it in GitHub Desktop.
Save noahhendrix/9119825 to your computer and use it in GitHub Desktop.
module Filterable
extend ActiveSupport::Concern
module ClassMethods
def filter(filtering_params)
filtering_params.reduce(self) do |relation, (scope_name, value)|
relation.public_send(scope_name, value) if value.present?
end
end
end
end
@monfresh
Copy link

Here's what it should look like:

filtering_params.reduce(self) do |relation, (scope_name, value)|
  value.present? ? relation.public_send(scope_name, value) : relation.all
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment