Z
Zouplaz
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 = '<br/>'
0.step(rubrique.level) { result += ' '}
result += rubrique.libelle + ' ' + link_to('+', :action => 'new',
arent_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
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 = '<br/>'
0.step(rubrique.level) { result += ' '}
result += rubrique.libelle + ' ' + link_to('+', :action => 'new',
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