On 21 aug, 13:16, Felix Schäfer <[email protected]> wrote:
> 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

Danke Felix!

I'm quite unsure whether this would limit the number of queries. I
already call children.each in my views, so this would probably, in
terms of performance, won't really help me. I was told I could perform
this using one single query, but that seems impossible. And that
brings me back to a point where I question the advantages of using
awesome_nested_set over using acts_as_tree in combination with
acts_as_list.

The thing is, it all made sense! And it would have been perfect.
--~--~---------~--~----~------------~-------~--~----~
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