From: Zouplaz Date: 2007-04-19T01:05:05+09:00 Subject: Recursive method not working Hi, I'm trying to display a hierarchical tree but there's something wrong with the method below. The result var is 'lost' between the calls - I mean, each "#{result}" contains the right value at the end of the method (I checked that), but that value is lost when returning to the upper level. I don't see why... Thanks for your help ! def affiche_arbre(rubriques) for rubrique in rubriques result = '
' 0.step(rubrique.level) { result += ' '} result += rubrique.libelle + ' ' + link_to('+', :action => 'new', :parent_id => rubrique) + ' ' unless rubrique.parent_id == nil result += link_to('E', :action => 'edit', :id => rubrique) + ' ' + link_to('D', :action => 'delete', :id => rubrique ) end if rubrique.children.size > 0 result += affiche_arbre(rubrique.children) end end "#{result}" end