Managing Hierarchical Data

You are probably looking for "acts_as_tree" (google for details).

--MarkusQ