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 779B

1234567891011121314151617181920212223242526
  1. acts_as_tree
  2. ============
  3. Specify this +acts_as+ extension if you want to model a tree structure by providing a parent association and a children
  4. association. This requires that you have a foreign key column, which by default is called +parent_id+.
  5. class Category < ActiveRecord::Base
  6. acts_as_tree :order => "name"
  7. end
  8. Example:
  9. root
  10. \_ child1
  11. \_ subchild1
  12. \_ subchild2
  13. root = Category.create("name" => "root")
  14. child1 = root.children.create("name" => "child1")
  15. subchild1 = child1.children.create("name" => "subchild1")
  16. root.parent # => nil
  17. child1.parent # => root
  18. root.children # => [child1]
  19. root.children.first.children.first # => subchild1
  20. Copyright (c) 2007 David Heinemeier Hansson, released under the MIT license