Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A DSL for filtering items (usually from some form of a data store).

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time


A DSL for filtering items (usually returned from some form of data store).



gem 'filterism'


gem install filterism


All examples use the ActiveRecordAdapter which is included with the gem. Other adapters may be created to meet your needs. These adapters generate the syntax to speak to whatever data store you need.


Adds .filter, .filterable_fields and .unfilterable_fields methods to all of you models Somewhere in your apps bootstrap/startup code:


Locally (in a model)

Adds .filter, .filterable_fields and .unfilterable_fields methods to only the User model

class User < ActiveRecord::Base
    include Filterism

Filterism was developed to fill the need of being able to filter Active Record results by aguments passed in the URL, however, it basically takes in a hash. Usually that hash would be "params" passed from the controller. The syntax of the keys in the hash control how the data is filtered.

It also adds a ".filterable_fields" method for you to limit by which fields the records may be filtered.



So as you see above, the syntax is [field]_is_[comparator]=value.

In the first argument, name is the [field] and [in] is the comparator.

In the second argument, salary is the [field] and [greater_than] is the comparator.


Filterable Fields

In the model you can limit which fields are filterable. This is optional. If this isn't in your model, all fields are filterable.

class User < ActiveRecord::Base
  filterable_fields :name

Unfilterable Fields

class User < ActiveRecord::Base
  unfilterable_fields :salary

The examples above are equivalent. If you have a long list of fields, you can use either a whitelist or blacklist depending on your needs


This gem adds the ".filter" class method to any active record class. You can pass in any hash, it doesn't have to operate from params. It will only look at keys that have the "_is_" syntax.

parser =
parsed_params = parser.parse(params)
users = User.filter(parsed_params).all


The current list of comparators are as follows. (taken right from the code)

    'equal_to' => '=',
    'not_equal_to' => '!=',

    'greater_than' => '>',
    'gt' => '>',
    'after' => '>',
    'greater_than_or_equal_to' => '>=',
    'gtet' => '>=',

    'less_than' => '<',
    'lt' => '<',
    'before' => '<',
    'less_than_or_equal_to' => '<=',
    'ltet' => '<=',

    'like' => 'LIKE',

    'in' => 'IN'

You can see that you can do things like [field]_is_gt=4000 or [field]_is_in=4,66,19

Please see for more examples of using ".filter"


  1. Fork it ([my-github-username]/filterism/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
Something went wrong with that request. Please try again.