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 <tomabroad@gmail.com>
hi & thx 4 ur time:<%= link_to h(y.title), y %> >
x = find.almost_all
<p>
<% for y in @x.ancestors.reverse %>
<% end %>
</p>
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
On Fri, Mar 26, 2010 at 1:37 PM, Lasse Bunk <lassebunk@gmail.com> wrote:
Tom,
Maybe it's just me but I don't quite understand... Could you explain what you're trying to achieve?
/Lasse2010/3/24 tom <tomabroad@gmail.com>
hi,
im using acts_as_tree and im not sure on how to group find-result.
x = find.almost_all
<p>
<% for y in @x.ancestors.reverse %>
<%= link_to h(y.title), page %> >
<% end %>
</p>
gives me a nice "breadcrum". but how is it possible to group the list lets say by the 1level or second level?
thx
--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment