ITeye博客

acts_as_tree

orcl_zhang · 2009-11-19 10:45 · rails · 编程语言 · Ruby · Markdown

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: [code="ruby"] def tree_ul(acts_as_tree_set, init=true, &block) if acts_as_tree_set.size > 0 ret = '

  • ' acts_as_tree_set.collect do |item| next if item.parent_id && init ret += '
  • ' ret += yield item ret += tree_ul(item.children, false, &block) if item.children.size > 0 ret += '' end ret += '

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。