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