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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 <tomabroad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
hi & thx 4 ur time: x = find.almost_all <p> <% for y in @x.ancestors.reverse %> <%= link_to h(y.title), y %> > <% 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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 <tomabroad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> hi & thx 4 ur time: > > > > x = find.almost_all > <p> > <% for y in @x.ancestors.reverse %> > <%= link_to h(y.title), y %> > > <% 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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> 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 <tomabroad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> >>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To unsubscribe from this group, send email to >>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >>> . >>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
thx! On Fri, Mar 26, 2010 at 3:06 PM, Lasse Bunk <lassebunk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > hi & thx 4 ur time: >> >> >> >> x = find.almost_all >> <p> >> <% for y in @x.ancestors.reverse %> >> <%= link_to h(y.title), y %> > >> <% 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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> 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 <tomabroad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>> >>>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>> To unsubscribe from this group, send email to >>>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >>>> . >>>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To unsubscribe from this group, send email to >>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >>> . >>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.