# LiveTree problem: non-AR model

**URL:** <https://www.ruby-forum.com/t/livetree-problem-non-ar-model/108372>\
**Category:** Rails\
**Created:** [July 2, 2007, 9:26pm UTC](https://www.ruby-forum.com/t/livetree-problem-non-ar-model/108372 "2007-07-02T21:26:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![damaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@damaris](https://www.ruby-forum.com/u/damaris)\
**Post date:** [July 2, 2007, 9:26pm UTC](https://www.ruby-forum.com/t/livetree-problem-non-ar-model/108372/1 "2007-07-02T21:26:32Z")

</div>

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? ☹

---

<div class="post-metadata">

**Author:** ![damaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@damaris](https://www.ruby-forum.com/u/damaris)\
**Post date:** [July 3, 2007, 5:32pm UTC](https://www.ruby-forum.com/t/livetree-problem-non-ar-model/108372/2 "2007-07-03T17:32:19Z")

</div>

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.
