DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Find All Children With Acts_as_tree

09.18.2010
| 6090 views |
  • submit to reddit
        #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
    

Comments

Snippets Manager replied on Wed, 2010/12/01 - 6:48am

I followed your previous posts on acts_as_tree. I tried to implement the code in http://snippets.dzone.com/posts/show/4388 (rails UI helper for acts_as_tree) Although it works fine, instead of displaying the evaluated HTML, the HTML itself is being displayed! I get outputs like this :
  • ibg
    • rgf
      • gn
        How do i get it not display the literal HTML ?