Acts As Ordered Tree plugin

Plugin details

This is a Rails ActiveRecord plugin which adds list capability to the standard acts_as_tree, as well as various movements of nodes/branches within the tree.

Websitehttp://ordered-tree.rubyforge.org/ Repositorysvn://rubyforge.org/var/svn/ordered-tree/acts_as_ordered_tree Author Brian D. Burns Tags order, tree LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install svn://rubyforge.org/var/svn/ordered-tree/acts_as_ordered_tree
  class Person < ActiveRecord::Base
    acts_as_ordered_tree :foreign_key => :parent_id,
                         :order       => :position
  end

  class CreatePeople < ActiveRecord::Migration
    def self.up
      create_table :people do |t|
        t.column :parent_id ,:integer ,:null => false ,:default => 0
        t.column :position  ,:integer
      end
      add_index(:people, :parent_id)
    end
  end


Which "in effect" sets up the following:

      belongs_to :parent,
                 :class_name  => Person,
                 :foreign_key => :parent_id

      has_many   :children,
                 :class_name  => Person,
                 :foreign_key => :parent_id,
                 :order       => :position

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, 11 months ago