LiveTree problem: non-AR model

Hi you all, I’m trying to use LiveTree with a non-AR model. As a trial,
I’ve written this model, that may be wrong. It just generates nodes.

class Elemento
attr_reader :nombre
attr_reader :id
attr_reader :parent
def initialize(value,id,parent)
@nombre = value
@id = id
@parent = parent
end
def self.find_root()
elem = Elemento.new(“Raiz”,0,nil)
elem
end
def children
children_array = []
i=1
for i in 1…4
children_array << Elemento.new(“Child”+i.to_s(),i,
self.find_root())
i=i+1
end
return children_array
end
end

On the other hand, my controller is:
live_tree :prueba_tree, :model => :elemento, :get_item_name_proc =>
Proc.new { |item| item.nombre }
def index
@root_prueba = Elemento.find_root()
end

However, even though in the view the root with the 4 children appears,
when click on any of them I get:
LiveTreeError: could not get data from server. When I click on a child,
the javascript alert does not print the name (just print “undefined”).

Any ideas? :frowning:

Well, the problem was that I wasn’t stating which are the exact children
of every node. The solution could be:

def initialize(value,id,parent)
@name = value
@id = id
@parent = parent
@children = []
end

def self.find_root()
@@root = Elemento.new(“Root”,0, nil)
@@child1 = Elemento.new(“Child 1”,1,@@root)
@@child2 = Elemento.new(“Child 2”,2,@@root)
@@child3 = Elemento.new(“Child 3”,3,@@root)
@@child4 = Elemento.new(“Child 4”,4,@@root)
@@child21 = Elemento.new(“Child 21”,21,@@child2)
@@child22 = Elemento.new(“Child 22”,22,@@child2)
@@child23 = Elemento.new(“Child 23”,23,@@child2)
@@child24 = Elemento.new(“Child 24”,24,@@child2)

@@root.children = [@@child1,@@child2,@@child3,@@child4]

@@child2.children = [@@child21,@@child22,@@child23,@@child24]

@@root
end

However, you will see a line in comments. If I add this line, the same
problem as the previous post appears. And now I am stating the parent
and the children of every node. What I am doing wrong?

Thanks.