The Ruby on Rails experts
Logo_144 ClearCove Software, Inc. :: Filterrific

Filterrific is a Rails Engine plugin that makes it easy to add filtering, searching, and sorting to your ActiveRecord lists.

Check out the live demo!

It comes with the following features:

  • Let your app's users search, filter and sort lists of ActiveRecord objects.
  • Persist filter settings in the HTTP session or DB (for saved searches).
  • Integrates with pagination.
  • Filters can be reset to default settings.
  • Relies on ActiveRecord scopes for building DB queries.
  • Shuttles filter settings from a filter UI to the controller and ActiveRecord.
  • Can be used for HTML/JS/JSON/XML response formats.

You only have to define the required ActiveRecord scopes and style your filter form and record lists.

I couldn't live without Filterrific. It makes it super easy to add user configurable reporting to my client projects.

Jeff Ward, Animikii

How to use it

Let's say you want a list of students that can be filtered by your app's users.

  1. Add the gem to your app

    # Gemfile
    gem 'filterrific'
    
  2. Add Filterrific to your Student model:

    filterrific(
      :default_settings => { :sorted_by => 'created_at_desc' },
      :filter_names => [
        :search_query,
        :sorted_by,
        :with_country_id,
        :with_created_at_gte
      ]
    )
    # define ActiveRecord scopes for
    # :search_query, :sorted_by, :with_country_id, and :with_created_at_gte
    
  3. Use Filterrific in StudentsController#index:

    def index
      @filterrific = Filterrific.new(Student, params[:filterrific])
      @students = Student.filterrific_find(@filterrific).page(params[:page])
    
      respond_to do |format|
        format.html
        format.js
      end
    end
    
  4. And finally build your view files as explained in the View API:

Filterrific in action

Example 1: A simple student list that can be filtered.

Learn about the example application →


Dependencies

  • Rails and ActiveRecord 3.x and 4
  • jQuery and Asset pipeline for form observers and spinner

License

MIT licensed

Copyright

Copyright (c) 2010 - 2014 Jo Hund.