RE: Ordering Results returned by has_many relationship

Since Order.order_lines is really just an array, then you can use the
sort feature of an array like this:

sorted = Order.order_lines.sort {|x,y| y.quantity <=> x.quantity }

Then do

sorted.each…

Hope this helps!