From: "Julian I. Kamil" Date: 2007-04-21T10:50:05+09:00 Subject: Re: looping through a tree from trunk to leaves This will do for 'MyModel': def view(args) args[:children].each do |child| printf("%03d %s%s\n", child.id, args[:level], child.class.name) view(:children => child.children, :level => "#{args[:level].gsub(/./, ' ')} ...") end end view(:children => MyModel.find(:all, :conditions => [ "parent_id IS NULL" ]), :level => '') Julian I. Kamil On Apr 20, 2:45 pm, Nanyang Zhan wrote: > I've just built a acts_as_tree model, > now I need to render it out as a tree structure in view. > and I also need a action method to loop through every row of the > database following the tree structure ( from root to it's branch, then > to the ends of the branch, then go back for other branches...). I think > both the view helper and action method need to use a similar loop style, > and this code may be popular, at lease useful. Is there any article > about this subject? > > I've get a view snip, btw:http://snippets.dzone.com/tag/acts_as_tree > > -- > Posted viahttp://www.ruby-forum.com/.