No commit activity in last 3 years
No release in over 3 years
Gem generates :filtered and :sorted scopes, can be easily used for building admin zone or other filterable sortable architecture.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.3
>= 0

Runtime

 Project Readme

FilterableSortable

Gem generates :filtered and :sorted scopes, can be easily used for building admin namespace or other filterable sortable architecture.

Installation

Add this line to your application's Gemfile:

gem 'filterable_sortable'

And then execute:

bundle

Or install it yourself as:

gem install filterable_sortable

Usage

Models

First of all include module into ActiveRecord::Base inherited class

include FilterableSortable

Controllers

In controllers add scopes to index action. I use 'will_paginate' gem, so here is method *.paginate(...)

@posts = Post.filtered(params[:filter]).ordered(params[:order]).paginate(page: params[:page], per_page: params[:per_page])

Views

Filtering and sorting

In views you can use links with params for order and filter. Example in Haml.

= link_to 'Name', posts_path(filter: {custom: :name}, order: {field: :name, direction: :ASC})

Searching

Simple search is also acts as filter, works as scope, already defined in gem, so enjoy it.

= form_tag posts_path do
    = text_field_tag :'filter[search]'

Contributing

  1. Fork it
  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 new Pull Request