Q: Grouping by date in descending order, but outputting records within date in ascending order With the following query I'm getting the records grouped by date in descending order, i.e. starting today and going back chronologically:
impressions = Impression.order(created_at: :desc).group_by {|impression| impression.created_at.to_date}

But when looping the nested Hash and outputting each day's records, I would like to have those in ascending order - i.e. starting with the first records created that particular day.
How could I acoomplish this?

A: Try this, but be aware, that for large collections, performance could be bad:
impressions = Impression.order(created_at: :desc).group_by {|impression| impression.created_at.to_date}
puts impressions.sort
# [[Sun, 05 Jan 2014, [#<Impressions id: 1..>,#<Impressions id: 2..>]], [Fr, 03 Jan 2014, [#<Impressions id: 3..>,#<Impressions id: 4..>]]]

But i don't understand, why you are sorting desc in your DB and then you want a asc order? Why don't you just use asc in your statement?
impressions = Impression.order(created_at: :asc).group_by {|impression| impression.created_at.to_date}

