#Find all children including grandchildren and children of their descendants recursively
#Using acts_as_tree
#inside example model Category


def all_children
all = []
self.children.each do |category|
all << category
root_children = category.all_children.flatten
all << root_children unless root_children.empty?
end
return all.flatten
end

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/wWOUyvlWm04/12283