Forum: Ruby on Rails Need help setting up and iterating thru a tree

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Peter J. (Guest)
on 2006-02-15 20:22

Newbie here.  Given the following table named Employee_Links:

ID  Emp_ID  Parent_ID
--  ------  ---------
1   200     100
2   300     100
3   300     200
4   400     100
5   500     400
6   500     300

I'd like to be able to generate a tree that looks like this:


Note that where 500's Parent_ID = 300 (row 6), 500 is linked to the
first 300 it finds in the tree diagram.

After some experimentation, it appears that ACTS_AS_TREE won't work
since I have nodes that will have >1 parent node.  Is there a simple way
to setup the relationship (HABTM?) AND the code that generates the tree
diagram?  I've looked at various similar examples online, and I have the
new Rails Recipes PDF book, but I haven't been able to figure this one
out without writing a lot of code, which I have a feeling is the wrong

This topic is locked and can not be replied to.