From: Nico Ritsche Date: 2008-01-29T15:55:40+09:00 Subject: Re: Hash Sorting Siep Korteling wrote: > Nico Ritsche wrote: >> result should look like this: >> >> pi_array_sorted = >> { 'general_event_types', [GeneralEventType1, GeneralEventType2, ..], >> 'prices', [Price1, Price2, ..], >> 'specific_event_types', [SpecificEventType1, SpecificEventType2, ..], >> 'general_event_types', [Teacher1, Teacher2, ..] } >> >> So the keys should be in alphabetical order, but they arent, (...) > > Well, they are, if the last 'general_event_types' is substituted with > 'teachers', what it probably should be. > I guess you want the values sorted. > > I don't now Rails, but hey, it's ruby. You can probably do > > @parent_items['teachers'] = Teacher.find(:all).sort > > in your second and following lines. Or: > > pi_array_sorted = @parent_items.sort.by{|key, value|value.sort!;key} > > to have your subarrays sorted and the keys as well in one go. > > Regards, > > Siep Hi Siep, yeah, that was a typo, the last general_event_types should be 'teachers'. But nevertheless, this is NOT what I get, its what I like to get! And I really only want to sort by key, as I explained erlier... Thanks, Nico -- Posted via http://www.ruby-forum.com/.