Chris@909: = AwesomeNestedSet Chris@909: Chris@909: 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. Chris@909: Chris@909: == What makes this so awesome? Chris@909: Chris@909: 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, and adds STI support. Chris@909: Chris@909: == Installation Chris@909: Chris@909: If you are on Rails 2.1 or later: Chris@909: Chris@909: script/plugin install git://github.com/collectiveidea/awesome_nested_set.git Chris@909: Chris@909: == Usage Chris@909: Chris@909: To make use of awesome_nested_set, your model needs to have 3 fields: lft, rgt, and parent_id: Chris@909: Chris@909: class CreateCategories < ActiveRecord::Migration Chris@909: def self.up Chris@909: create_table :categories do |t| Chris@909: t.string :name Chris@909: t.integer :parent_id Chris@909: t.integer :lft Chris@909: t.integer :rgt Chris@909: end Chris@909: end Chris@909: Chris@909: def self.down Chris@909: drop_table :categories Chris@909: end Chris@909: end Chris@909: Chris@909: Enable the nested set functionality by declaring acts_as_nested_set on your model Chris@909: Chris@909: class Category < ActiveRecord::Base Chris@909: acts_as_nested_set Chris@909: end Chris@909: Chris@909: Run `rake rdoc` to generate the API docs and see CollectiveIdea::Acts::NestedSet::SingletonMethods for more info. Chris@909: Chris@909: == View Helper Chris@909: Chris@909: The view helper is called #nested_set_options. Chris@909: Chris@909: Example usage: Chris@909: Chris@909: <%= f.select :parent_id, nested_set_options(Category, @category) {|i| "#{'-' * i.level} #{i.name}" } %> Chris@909: Chris@909: <%= select_tag 'parent_id', options_for_select(nested_set_options(Category) {|i| "#{'-' * i.level} #{i.name}" } ) %> Chris@909: Chris@909: See CollectiveIdea::Acts::NestedSet::Helper for more information about the helpers. Chris@909: Chris@909: == References Chris@909: Chris@909: You can learn more about nested sets at: Chris@909: Chris@909: http://www.dbmsmag.com/9603d06.html Chris@909: http://threebit.net/tutorials/nestedset/tutorial1.html Chris@909: http://api.rubyonrails.com/classes/ActiveRecord/Acts/NestedSet/ClassMethods.html Chris@909: http://opensource.symetrie.com/trac/better_nested_set/ Chris@909: Chris@909: Chris@909: Copyright (c) 2008 Collective Idea, released under the MIT license