`
orcl_zhang
  • 浏览: 234927 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

acts_as_tree

阅读更多
acts_as_tree:
http://snippets.dzone.com/tag/acts_as_tree

------------
// This takes a collection of acts_as_tree objects and creates a unordered list.
//
// Put this in your helper:
 def tree_ul(acts_as_tree_set, init=true, &block)
    if acts_as_tree_set.size > 0
      ret = '<ul>'
      acts_as_tree_set.collect do |item|
        next if item.parent_id && init
        ret += '<li>'
        ret += yield item
        ret += tree_ul(item.children, false, &block) if item.children.size > 0
        ret += '</li>'
      end
      ret += '</ul>'
    end
  end



// ... and this in your view:
 <%= tree_ul(@acts_as_list_collection) {|item| link_to h(item.name), :action => 'edit', :id => item } %>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics