Skip to content
rails engine plugin for filtering active_record model objects
Ruby JavaScript
Find file
Pull request Compare This branch is 11 commits ahead, 30 commits behind berk:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
app
config
lib
script
spec
test
.gitignore
.rspec
.rvmrc
CHANGELOG.rdoc
Gemfile
Gemfile.lock
MIT-LICENSE
README.rdoc
Rakefile
will_filter.gemspec

README.rdoc

WillFilter

will_filter is a Rails engine plugin that provides a GUI for filtering your ActiveRecord models.

Preamble

If you ever had to build an admin tool for your web site that displayed a list of objects that can be filtered using various criteria, this plugin will make your life easier. Adding a filtered page can now be a matter of adding two lines of code - one to your controller and one to your view. See examples below.

Installation Instructions

Add the following gems to your Gemfile:

gem 'will_filter', "~> 3.1.0" 
gem 'kaminari'

And run:

$ bundle

To configure and initialize will_filter engine, run the following commands:

$ rails generate will_filter  
$ rake db:migrate

At the top of your routes.rb file, add the following line:

mount WillFilter::Engine => "/will_filter"

Examples

To add a filtered result-set to your controller use the following method call:

class UsersController < ApplicationController

  def index
    @users = User.filter(:params => params)    
  end

end

Note: 'User' is a Rails ActiveRecord model

Now all you have to do is create a view for this action and add the following tag where you want the filter to be rendered:

<%= will_filter_tag(@users) %>

And optionally you can do (for results table):

<%= will_filter_table_tag(@users) %>

That's it. This will render a filter box with various conditions, operators and values for the model object you selected.

Below are a couple of screenshot of what the filter looks like when it is rendered on a page:

This plugin comes with a dummy test project. To try out some of the examples, run the following commands:

$ git clone git://github.com/berk/will_filter.git
$ cd will_filter/test/dummy  
$ rake db:migrate 
$ rake samples:init
$ rails server

Open your browser and point to:

http://localhost:3000

If you have any questions, comments or suggestions, email me at theiceberk@gmail.com

Authors and credits

Authors

Michael Berkovich

Something went wrong with that request. Please try again.