# Sorting data properly

**URL:** <https://www.ruby-forum.com/t/sorting-data-properly/110903>\
**Category:** Rails\
**Created:** [July 31, 2007, 11:00pm UTC](https://www.ruby-forum.com/t/sorting-data-properly/110903 "2007-07-31T23:00:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![randall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b38774/32.png) [@randall](https://www.ruby-forum.com/u/randall)\
**Post date:** [July 31, 2007, 11:00pm UTC](https://www.ruby-forum.com/t/sorting-data-properly/110903/1 "2007-07-31T23:00:57Z")

</div>

Greetings all,

As a preface, I’m not actually a programmer, I’m a network  
administrator. The ruby programmer at work just left to work at a  
startup, and until a replacement can be found I’m trying to fill in. So  
if I act ignorant, it’s because I am. Try and bear with me…

I’ve got a page that contains a bunch of data. For the list, the  
controller has the following

def list  
@schedules = Schedule.find :all,  
:conditions=\>[“date between ? and ?”,@starts, @ends],  
:order=\>‘date asc, period, collection\_point\_id, lane\_type’,  
:include=\>‘collection\_point’  
end

On the view page, we have this (I think this covers the pertinent code)

\<% @schedules.group\_by{|s| s.date }.sort\_by{|d,s| d}.each do |date,  
schedules| %\>

My problem is I need the data grouped by date, and then sorted by  
period. Unfortunately, I can’t seem to get my head around iteration in  
Ruby yet, so I’m not sure how to change sort\_by call to make it work (in  
fact, I’m not entirely sure what d and s are)

Any thoughts? I can post more code, but I’m not entirely sure what to  
post. Full versions of the controller, model, and associated view are  
all enclosed in the zip.

Thanks,  
mike
