Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 91 lines (53 sloc) 2.604 kb
9fe7316 @benedikt Initial commit to filter_fu.
authored
1 = filter_fu
2
af777bb @benedikt Updated Readme and License
authored
3 This Ruby on Rails plugin adds a <tt>.filtered_by</tt> method to your models. It accepts a hash of filters that are applied using scopes. In addition the plugin adds some view helpers to easily build filter forms.
9e6493f @benedikt Added readme.
authored
4
5 == Install
6
7 You can install filter_fu as a gem or as a rails plugin.
8
9 === Install as gem
10
af777bb @benedikt Updated Readme and License
authored
11 To install the filter_fu gem, simply add it to your Gemfile:
9e6493f @benedikt Added readme.
authored
12
af777bb @benedikt Updated Readme and License
authored
13 gem 'filter_fu'
14
15 In order to get the latest development version of filter_fu:
16
17 gem 'filter_fu', :git => 'git://github.com/benedikt/filter_fu.git'
9e6493f @benedikt Added readme.
authored
18
af777bb @benedikt Updated Readme and License
authored
19 and run
9e6493f @benedikt Added readme.
authored
20
af777bb @benedikt Updated Readme and License
authored
21 bundle install
9e6493f @benedikt Added readme.
authored
22
23 == Usage
24
25 === Models
26
27 To enable filter_fu on a model, simply add one line to its definition:
28
af777bb @benedikt Updated Readme and License
authored
29 class Project < ActiveRecord::Base
9e6493f @benedikt Added readme.
authored
30 filter_fu
31 end
50fdb19 @benedikt Removed whitespace
authored
32
9e6493f @benedikt Added readme.
authored
33 Let's say you don't want your Projects list filtered by its +hidden+ column. You can easly
34 tell filter_fu to ignore certian named scopes or columns:
50fdb19 @benedikt Removed whitespace
authored
35
af777bb @benedikt Updated Readme and License
authored
36 class Project < ActiveRecord::Base
9e6493f @benedikt Added readme.
authored
37 filter_fu :except => [:hidden]
38 end
39
50fdb19 @benedikt Removed whitespace
authored
40 Of course this also works the other way round using the <tt>:only</tt> option to only allow filtering
9e6493f @benedikt Added readme.
authored
41 for the given named scopes or columns:
42
af777bb @benedikt Updated Readme and License
authored
43 class Project < ActiveRecord::Base
9e6493f @benedikt Added readme.
authored
44 filter_fu :only => [:starts_on, :ends_on]
45 end
50fdb19 @benedikt Removed whitespace
authored
46
9e6493f @benedikt Added readme.
authored
47 Once you enabled filter_fu on your model it provides a filtered_by method.
48
49 Project.filtered_by(params[:filter])
50 Project.filtered_by(params[:filter]).some.named_scopes
af777bb @benedikt Updated Readme and License
authored
51 Project.some.other.scopes.filtered_by(params[:filter])
50fdb19 @benedikt Removed whitespace
authored
52
9e6493f @benedikt Added readme.
authored
53
54 === Helper
55
56 filter_fu comes with helpers to simplify the generation of filter forms:
57
af777bb @benedikt Updated Readme and License
authored
58 <%= filter_form do |f| %>
9e6493f @benedikt Added readme.
authored
59 # f is a ActionView::Helpers::FormBuilder
60 <% end %>
61
62 You can also specify a name for the filter (Default is <tt>:filter</tt>). This way you're able to have multiple filters on the same page.
63
af777bb @benedikt Updated Readme and License
authored
64 <%= filter_form_for(:product_filter) do |f| %>
9e6493f @benedikt Added readme.
authored
65 # f is a ActionView::Helpers::FormBuilder
50fdb19 @benedikt Removed whitespace
authored
66 <% end %>
9e6493f @benedikt Added readme.
authored
67
50fdb19 @benedikt Removed whitespace
authored
68 filter_fu will automatically include all other parameters for the current page (ie. pagination parameters) within the form.
9e6493f @benedikt Added readme.
authored
69 If you wish to explicitly exclude some you can do this by passing an array as :ignore_parameters option.
70
af777bb @benedikt Updated Readme and License
authored
71 <%= filter_form_for(:product_filter, :ignore_parameters => [:page]) do |f| %>
9e6493f @benedikt Added readme.
authored
72 # f is a ActionView::Helpers::FormBuilder
73 <% end %>
9fe7316 @benedikt Initial commit to filter_fu.
authored
74
5e3dfc6 @benedikt Added configuration settings for ignore_parameters
authored
75 It's possible to add default values for <tt>:ignore_parameters</tt>. Simply add something like this to your initializers:
af777bb @benedikt Updated Readme and License
authored
76
5e3dfc6 @benedikt Added configuration settings for ignore_parameters
authored
77 config.filter_fu.ignore_parameters = [:param_to_ignore]
af777bb @benedikt Updated Readme and License
authored
78
79 == Known issues
80
81 See http://github.com/benedikt/filter_fu/issues
82
83 == Repository
84
85 See http://github.com/benedikt/filter_fu and feel free to fork it!
86
87
9fe7316 @benedikt Initial commit to filter_fu.
authored
88 == Copyright
89
af777bb @benedikt Updated Readme and License
authored
90 Copyright (c) 2009, 2010 Benedikt Deicke. See LICENSE for details.
Something went wrong with that request. Please try again.