You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.rdoc 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. = AwesomeNestedSet
  2. 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.
  3. == What makes this so awesome?
  4. 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.
  5. == Installation
  6. If you are on Rails 2.1 or later:
  7. script/plugin install git://github.com/collectiveidea/awesome_nested_set.git
  8. == Usage
  9. To make use of awesome_nested_set, your model needs to have 3 fields: lft, rgt, and parent_id:
  10. class CreateCategories < ActiveRecord::Migration
  11. def self.up
  12. create_table :categories do |t|
  13. t.string :name
  14. t.integer :parent_id
  15. t.integer :lft
  16. t.integer :rgt
  17. end
  18. end
  19. def self.down
  20. drop_table :categories
  21. end
  22. end
  23. Enable the nested set functionality by declaring acts_as_nested_set on your model
  24. class Category < ActiveRecord::Base
  25. acts_as_nested_set
  26. end
  27. Run `rake rdoc` to generate the API docs and see CollectiveIdea::Acts::NestedSet::SingletonMethods for more info.
  28. == View Helper
  29. The view helper is called #nested_set_options.
  30. Example usage:
  31. <%= f.select :parent_id, nested_set_options(Category, @category) {|i| "#{'-' * i.level} #{i.name}" } %>
  32. <%= select_tag 'parent_id', options_for_select(nested_set_options(Category) {|i| "#{'-' * i.level} #{i.name}" } ) %>
  33. See CollectiveIdea::Acts::NestedSet::Helper for more information about the helpers.
  34. == References
  35. You can learn more about nested sets at:
  36. http://www.dbmsmag.com/9603d06.html
  37. http://threebit.net/tutorials/nestedset/tutorial1.html
  38. http://api.rubyonrails.com/classes/ActiveRecord/Acts/NestedSet/ClassMethods.html
  39. http://opensource.symetrie.com/trac/better_nested_set/
  40. Copyright (c) 2008 Collective Idea, released under the MIT license