Better nested set
http://agilewebdevelopment.com/plugins/betternestedset
ここにあります。どういうものかというと、acts_as_nested_setを拡張して
便利にしたものです。
acts_as_nested_set + acts_as_tree + 便利= better_nested_set
といった感じです。
インストール方法
./script/plugin install http://opensource.symetrie.com/svn/better_nested_set/trunk
ただ、trunkという名前になるので、リネームした方がいい気がします。
使えるメソッド一覧
- move_to_child_of 別の場所にぶら下げる
- move_to_right_of別の場所にぶら下げる
- move_to_left_of別の場所にぶら下げる
- root 一番元の親
- roots 一番トップの親を配列で返す
- level 枝の深さ
- ancestors 一番元の親から直接の親までの配列
- self_and_ancestors 上+自分
- siblings 自分と同じレベルの要素の配列
- self_and_siblings 上+自分
- children_count 子の数
- children 直接の子の配列
- all_children 子すべての配列(孫などを含む)
- left_col_name 左の名前
- right_col_name 右の名前
- parent_col_name 親の名前