i have a table of data, which can have each other as parents or childs, its handled with the field parent_id (I am using the act_as_tree gem)
the first level items have 0 as parent_id
there could be an infinite number of children. I want to output as JSON. the final output shud be something like this
{
"feild1": "dd",
"filed2": "ee",
"child" : {
"feild1": "dd",
"filed2": "ee",
}
"child" : {
"feild1": "dd",
"filed2": "ee",
"child" : {
"feild1": "dd",
"filed2": "ee",
}
}
}
so far i all i have is this
def coa_tree
@roots = Coa.find(:all, :conditions => ['parent_id = ?', 0])
@response = @roots
@roots.each do |root|
logger.debug "roots each"
output = root
root.children.each do |child|
output = {:child => output, :child => child}
end
end
respond_with(@response)
end
clearly i haven't even come close to solving the problem. If someone could point me to the right direction i would really appreciate it. maybe there is a plugin that i don't know about that would help me solve this. thanks.