selectable_attr

155 views
Skip to first unread message

Takeshi Akima

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

selectable_attrというRailsのプラグインを公開しました。

モデルに以下のようにカラムの定義を書くと、
class Product < ActiveRecord::Base
selectable_attr :media do
entry '01', :book, '書籍'
entry '02', :cd, 'CD'
entry '03', :cdrom, 'CD-ROM'
entry '04', :dvd, 'DVD'
entry '05', :bluray, 'Blueray'
entry '06', :download, 'ダウンロード'
end

multi_selectable_attr :genre, :convert_with => :comma_string do
entry '01', :technology, 'テクノロジ'
entry '02', :history, '歴史'
entry '03', :politic, '政治'
entry '04', :action, 'アクション'
entry '05', :education, '教育'
entry '06', :documentary, 'ドキュメンタリー'
end
end

ビューでは以下のようなメソッドを使うことができて
<p>
<%= f.label :media %><br />
<%= f.radio_button_group :media %>
</p>
<p>
<%= f.label :genre %><br />
<%= f.check_box_group :genre %>
</p>

f.radio_button_group は <input type="radio" ... />とラベルを要素の数だけ
f.check_box_groupは <input type="checkbox" ... />とラベルを要素の数だけ
出力します。

また、f.radio_button_groupの代わりに、
<%= f.select :media %>
と記述することも可能です。


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

簡単なサンプルアプリは、
http://rbc-incubator.googlecode.com/svn/akm2000/applications/trunk/selectable_attr_example
で公開しております。

モデルとしては色々なメソッドを用意しており、ドキュメントなどを
どんどん公開していく予定ですが、ご協力していただけると非常に
助かります。もしちょっとやってみようかなと思ったら秋間あるいは
rbc-incubator(rbc-in...@googlegroups.com)までご連絡ください。
お待ちしております。

Reply all
Reply to author
Forward
0 new messages