pelargir / finder_filter

An easy way to add common finders to your Rails controllers.

This URL has Read+Write access

finder_filter / README
ad77ae7a » Matthew Bass 2008-08-08 initial import 1 = Synthesis
2
3 An easy way to add common finders to your Rails controllers.
4
5 == Installation
6
7 gem sources -a http://gems.github.com (you only have to do this once)
8 sudo gem install pelargir-finder_filter
9
10 == Usage
11
77e1cf04 » Matthew Bass 2008-08-08 added usage doc 12 finder_filter is intended to replace one-off before filters that you might
13 commonly write in your Rails controllers. For example:
14
15 class UsersController < ActionController::Base
16 before_filter :find_user, :only => [:show, :edit]
17
18 def show; end
19 def edit; end
20
21 def find_user
22 @user = User.find(params[:id)
23 end
24 end
25
26 finder_filter reduces this pattern to a single line:
27
28 class UsersController < ActionController::Base
29 finder_filter :user, :only => [:show, :edit]
30
31 def show; end
32 def edit; end
33 end
34
35 To find based on a column other than ID:
36
37 finder_filter :user, :by => :name
38 # equivalent to:
39 # @user = User.find_by_name(params[:id])
40
41 To find based on a param other than ID:
42
43 finder_filter :user, :param => :permalink
44 # equivalent to:
45 # @user = User.find(params[:permalink])
46
47 The standard Rails :only and :except options can also be used:
48
49 before_filter :find_user, :only => [:show, :edit]
50 before_filter :find_user, :except => [:index]
ad77ae7a » Matthew Bass 2008-08-08 initial import 51
52 == Git
53
54 git://github.com/pelargir/finder_filter.git
55
56 == Contributors
57
58 Matthew Bass