acts_as_tree help

Hi all...   I created a table having a tree structure using acts_as_tree. Now I need to access all the parents, grandparents etc upto the root of a particular node. Also all the children upto leaf node. I used particular_node_id.children() method to access the immediate children and particular_node_id.ancestors() to access the immediate parents of a node.

Please help me to find all the parents upto root and all the children upto leaf of a particular node.

Thanks Regards Suneeta

I used this code to get all the ancestors for a given node:

def ancestors(list=) if parent.nil? list << parent else list << parent parent.ancestors(list) end list.compact end

You should use act_as_nested_set or better_nested_set. They are better optimized for this, and it has built-in methods to accomplish what you are asking for.