Am 21.08.2009 um 12:19 schrieb jhaagmans:

> @attributes = root_attribute.self_and_descendants
>
> However, when I put the following in my views to be able to descend
> into the model:
>
> <% @attributes.root.children.each do |attribute| %>
> ...
> <% end %>


I think I now see where the problem is. To be quite honest, I'm  
surprised this even works, because @attributes is a set, and you  
shouldn't be able to call root on it. Anyway, self_and_descendants  
gets you a flat set, from which you could reconstruct a tree on your  
own, but I don't think that would be that easy.

What I can come up right now is a way to cut the calls down to the  
number of nodes with children with something like:

"""
def my_awesome_helper(root)
   result = "<ul>" + "<li>" + root.someattribute
   if root.children {
     root.children.each do |child|
       result += my_awesome_helper(child)
     end
   end
   result += "</li>" + "</ul>"
end
"""
(yeah, ugly, and I'm not even sure the syntax is right, but you get  
the idea)

You'd then just have to call the helper on the root node in your view.


Mit freundlichen Grüßen,

Felix Schäfer


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to