One of the things sorely missing from Rails (and with good reason) is a function to find all the children in a tree. Below is my attempt at it, you can drop it in any model that acts_as_tree and call all_children to get a flattened list of all children, grandchildren, etc.
def all_children
all_children = []
all_children << list_children(self)
return all_children.flatten
end
private
def list_children(branch)
all_children = []
for child in branch.children
all_children << list_children(child)
end
if branch.children.empty?
return branch
else
all_children << branch
return all_children
end
end