May 23 2006
User: cedric
Category: Ruby on Rails
Tags:

representation d'arbre

Representation d’elements, Element est défini comme ‘act_as_tree’

Dans un controller (element_controller.rb):

def showtreelist(item)
  @tree+="
    " if item.children.empty? #action else for child in item.children @tree+="
  • #{child.name}
  • " showtreelist(child) end end @tree+="
" end
def showtree
  @root=Element.find(0)
  @tree=@root.name.to_s
  showtreelist(@root)
end

Dans la vue de l’action showtree (showtree.rhtml):

<%= @tree %>

comments : 0 Add comment

Back
Log in

Quick links

Localization

Search

weather


  • metric us

gallery

Last comments

Categories

  • categories

nabaztag

  • message

    left
    right
    voice
    speed
    pitch

hcard