Ruby on Rails
Double Filter Plugin

A plugin from cuzic.

DoubleFilter
==================

`Double Filter’ is very useful plugin when you want to add a filtering feature.
`Double Filter’ assumes that you want to filter by two columns and the two columns are independent of each other.

Usage
==================
0. Prepare your controller to add `Double Filter’ feature `Double Filter’ needs some controller to apply. In this example, we assume the name of controller is `FooController’ and is defined in `foo_controller.rb’.
1. Write configuration file , config/double_filter.yml Configuration file is somethin like below:

 foo:                     # controller name
   model: Foo             # model name
   column0: bar_column    # db column name
   abbrev0: bar           # element id and rhtml filename
   column1: baz_column
   abbrev1: baz
   recordset: foos   # name of the array of ActiveRecord in your list.rhtml,
   pages: foo_pages  # name of pagination object in your list.rhtml

2. Generation of double filter views

 > ruby script/generate double_filter_view foo
 create app/views/foo/_double_filter.rhtml
 create app/views/foo/filtered_list.rhtml

3. Edit a controller file

In you `app/controllers/foo_controller.rb’

 class FooController
   include DoubleFilter
   double_filter "foo"   # the controller name defined in double_filter.yml
   ...
 end

4. Add some lines into existing files.
In your `index.rhtml’ , `list.rhtml’ or `_list.rhtml’

 <%= render_partial "double_filter" %>

In the corresponding controller method, please invoke
`collect_column_information’ method.

All your actions that conrresponding view templates have partial rendering of `Double Filter’ need to invoke collect_column_information in advance.

example:

 def list
   collect_column_information
   ...
 end

5. Edit `_double_filter.rhtml’ and `filtered_list.rhtml’ as you like.

6. Have Fun.

Customization
==================
You can customize behavior of `Double Filter’ thanks to Ruby’s dynamic feature.

Just redefine the methods, when you want to customize behavior of some methods,

example:

 class FooController < ApplicationController
   include DoubleFilter
   double_filter "foo"   # the controller name defined in double_filter.yml

   def filtered_list
     # your specific behavior
   end
 end

Have Fun!

contact information: cuzic atmark cuzic.com

svn: http://opensvn.csie.org/double_filter/trunk