Grouping and acts_as_tree

hi,

im using acts_as_tree and im not sure on how to group find-result.

x = find.almost_all

<% for y in @x.ancestors.reverse %> <%= link_to h(y.title), page %> > <% end %>

gives me a nice “breadcrum”. but how is it possible to group the list
lets
say by the 1level or second level?

thx

Tom,

Maybe it’s just me but I don’t quite understand… Could you explain
what
you’re trying to achieve?

/Lasse

2010/3/24 tom [email protected]

hi & thx 4 ur time:

x = find.almost_all

<% for y in @x.ancestors.reverse %> <%= link_to h(y.title), y %> > <% end %>

results in:

Root > child A > child A1
Root > child A >
Root > child B > child B999 > child C245
Root > child D > child B41
Root > child A > child Axyz


how can i group the list above lets say by the second level, eg like
this:

CHILD A
Root > child A > child A1
Root > child A >
Root > child A > child Axyz

CHILD B
Root > child B > child B999 > child C245

CHILD D
Root > child D > child B41

or even by length after grouping by title (CHILD A):
Root > child A >
Root > child A > child A1
Root > child A > child Axyz

You can do it like this:

this array is just my representation of your data

paths = [[“Root”, “child A”, “child A1”],
[“Root”, “child A”],
[“Root”, “child B”, “child B999”, “child C245”],
[“Root”, “child D”, “child B41”],
[“Root”, “child A”, “child Axyz”]]

you can do the grouping like this

groups = paths.group_by{ |p| p[1] }

puts groups.inspect # this is a hash

/Lasse

2010/3/26 tom [email protected]

thx!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs