Every repository with this icon (
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Sat Jun 07 21:02:49 -0700 2008 | [brandon] |
| |
MIT-LICENSE | Thu Oct 18 06:46:41 -0700 2007 | [brandon] |
| |
README.rdoc | Mon Jun 09 10:15:01 -0700 2008 | [masayuki] |
| |
Rakefile | Sat Jun 07 21:02:49 -0700 2008 | [brandon] |
| |
init.rb | Sat May 17 12:44:32 -0700 2008 | [brandon] |
| |
lib/ | Mon Jun 09 10:15:01 -0700 2008 | [masayuki] |
| |
test/ | Mon Jun 09 10:20:42 -0700 2008 | [masayuki] |
AwesomeNestedSet
Awesome Nested Set is an implementation of the nested set pattern for ActiveRecord models. It is replacement for acts_as_nested_set and BetterNestedSet, but awesomer.
What makes this so awesome?
This is a new implementation of nested set based off of BetterNestedSet that fixes some bugs, removes tons of duplication, adds a few useful methods, callbacks, adds STI support and adds 2 very helpful view helpers for select boxes.
Installation
If you are on edge rails:
script/plugin install git://github.com/collectiveidea/awesome_nested_set.git
If you are not on edge rails:
git clone git://github.com/collectiveidea/awesome_nested_set.git vendor/plugins/awesome_nested_set
Usage
To make use of awesome_nested_set, your model needs to have 3 fields: lft, rgt, and parent_id:
class CreateCategories < ActiveRecord::Migration
def self.up
create_table :categories do |t|
t.string :name
t.integer :parent_id
t.integer :lft
t.integer :rgt
end
end
def self.down
drop_table :categories
end
end
Enable the nested set functionality by declaring acts_as_nested_set on your model
class Category < ActiveRecord::Base
acts_as_nested_set
end
Run `rake rdoc` to generate the API docs and see CollectiveIdea::Acts::NestedSet::SingletonMethods for more info.
View Helpers
- #nested_set_options_for_select - returns an array of objects suitable for select helpers
- #nested_set_options_for_select_without_impossible_moves - similar to nested_set_options_for_select, but contains only items that are possible to move to
See CollectiveIdea::Acts::NestedSet::Helper for more information about the helpers.
References
You can learn more about nested sets at:
http://www.dbmsmag.com/9603d06.html http://threebit.net/tutorials/nestedset/tutorial1.html http://api.rubyonrails.com/classes/ActiveRecord/Acts/NestedSet/ClassMethods.html http://opensource.symetrie.com/trac/better_nested_set/
Copyright © 2008 Collective Idea, released under the MIT license




