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

Filterrific is a Rails Engine plugin that makes it easy to filter, search, and sort your ActiveRecord lists.

Live demo using classic Rails views.

Live demo of JSON API using React and Mobx.

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

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

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
     filterrific(
       default_filter_params: { sorted_by: 'created_at_desc' },
       available_filters: [
         :sorted_by,
         :search_query,
         :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:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
     def index
       @filterrific = initialize_filterrific(
         Student,
         params[:filterrific]
       ) or return
       @students = @filterrific.find.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, 4.x, or 5.x
  • jQuery and Asset pipeline for form observers and spinner

License

MIT licensed