finder_formプラグイン

1 view
Skip to first unread message

秋間武志

unread,
Sep 30, 2008, 6:19:01 AM9/30/08
to mem...@rubybizcommons.jp, rbc-in...@googlegroups.com
秋間です。

本日2つめのプラグインは finder_formです。
これは一覧画面等で条件を入力するためのフォームと
マッピングされるクラスを定義するためのクラスを提供します。

http://code.google.com/p/rbc-incubator/source/browse/akm2000/applications/trunk/finder_form_example/app/models/person.rb
という風に定義して、

コントローラのindexアクションはこんな感じ、
def index
@finder_form = Person::FinderForm.new(params[:finder_form])

@peoples = Person.find(:all, @finder_form.to_find_options)

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @peoples }
end
end

ビューにはこんな感じ
http://code.google.com/p/rbc-incubator/source/browse/akm2000/applications/trunk/finder_form_example/app/views/people/_finder_form.html.erb
で定義してあげると、findメソッドやpaginateメソッドのオプションを
生成してくれます。


上のサンプルでも分かると思いますが、単一のテーブルではなく
複数のテーブル間のjoinを定義しておけば、それが条件によって必要な
場合にのみ自動的に:joinsオプションを生成してくれたりするので、
難しい検索条件を作る際などに便利だと思います。

このプラグインは
ruby script/plugin install
http://rbc-incubator.googlecode.com/svn/akm2000/plugins/trunk/finder_form
でインストールできます。

またサンプルアプリケーションは
svn checkout http://rbc-incubator.googlecode.com/svn/akm2000/applications/trunk/finder_form_example
でチェックアウトできます。

こちらのプラグインもドキュメントやサンプルの作成に
ご協力して頂ける方を募集しています。興味がある方は
秋間あるいはrbc-incubator(rbc-in...@googlegroups.com)までご連絡ください。

宜しくお願い致します。

Reply all
Reply to author
Forward
0 new messages