Hello, i want t know where can i foundd how to get all the childs from a
user id, including all, recursivily.
Regards,
Hello, i want t know where can i foundd how to get all the childs from a
user id, including all, recursivily.
Regards,
this works, # either way.
def get_children(page, collection)
page.children.each { |p|
collection << p ; get_children(p, collection)
}
end
def get_tree
tree = []
page = Page.find(params[:id])
get_children(page, tree)
render_text tree.collect{|p| p.id }.join(", ")
rescue
render_text "enter an id"
end
then call get_tree/10 and it will find the branch under page#10.
hope this helps somewhat, but i would strongly reccomend looking up
other things aside from this recursive func, as it is a very slow
method, and if you have a lot of children, this could take ages.
either way, enjoy.
shai
def get_children(page, collection) page.children.each { |p| collection << p ; get_children(p, collection) } end def get_tree tree = [] page = Page.find(params[:id]) get_children(page, tree) render_text tree.collect{|p| p.id }.join(", ") rescue render_text "enter an id" end
how i have to call the method, because it throw a nil object, calling
this way:
<[email protected] do |m|%>
<%m.hijos.each do |c|%>
<%=c%>
<%end%>
<%end%>
because i have acts_as_tree in other model this is why
@member.matix…, so in member i got has_many :matrix
I found this, i think it will be helpful, the problem is if i specify,
for example 4, to see the members in the level 4, it will bring all the
members to level 4, but i just want the ones who ares in level 4, from
determinate user
def matrix(depth, list=[])
unless depth.zero?
children.each do |child|
list.push(child.member.name)
child.hijoss(depth-1, list)
end
end
list
end
i have tried:
def matrix2(depth)
list = matrix(depth)-matrix(depth-1)
end
but i dont like that way, i think there could be a better solution like
.include?, exclude, i dont know relly :P, please some help
regrads,
PLeased some help:
i want to load an hash array like this, but i dont get it:
def All(depth, list=[])
level=0
unless depth.zero?
level += 1
list[level] = []
children.each do |child|
list[level].push(child.member)
child.All(depth-1, list)
end
end
list
end
any ideas?
seems like i found with this :S
def matrix(depth)
list = matrixx(depth-1)
list.flatten - matrixx(depth-2).flatten
end
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs