How-to sorting after group_by?

I tried this code:

voiplogs = where([‘data > ? AND data < ?’, start_date,
end_date]).group_by(&:cli)

it’s works, but how add also sort by :cli

Tanks to all
Fabio

On Wed, Aug 3, 2011 at 4:28 PM, Fabio Chiarelli
[email protected]wrote:

I tried this code:

voiplogs = where([‘data > ? AND data < ?’, start_date,
end_date]).group_by(&:cli)

voiplogs = where([‘data > ? AND data < ?’, start_date,
end_date]).order(‘cli ASC’).group_by(&:cli)

“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.

In ruby 1.9.2,

…group_by(&:cli).sort

Otherwise, you can’t because hashes are unordered by nature. You can
sort the keys and then access the hash using the sorted keys. Or, you
can use ActiveSupport::OrderedHash, and try to figure out how to
initialize it when you have a Hash.