Never been to DZone Snippets before?

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

About this user

Matt Mitchell

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Rails UL Helper for acts_as_tree

// This takes a collection of acts_as_tree objects and creates a unordered list.
//
// Put this in your helper:

   1  
   2    def tree_ul(acts_as_tree_set, init=true, &block)
   3      if acts_as_tree_set.size > 0
   4        ret = '<ul>'
   5        acts_as_tree_set.collect do |item|
   6          next if item.parent_id && init
   7          ret += '<li>'
   8          ret += yield item
   9          ret += tree_ul(item.children, false, &block) if item.children.size > 0
  10          ret += '</li>'
  11        end
  12        ret += '</ul>'
  13      end
  14    end


// ... and this in your view:
   1  
   2    <%= tree_ul(@acts_as_list_collection) {|item| link_to h(item.name), :action => 'edit', :id => item } %>
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS