Forum: Ruby on Rails RE: Ordering Results returned by has_many relationship.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E94ca0face81fe54d0486b397ea3412d?d=identicon&s=25 Campano, David (Guest)
on 2006-05-03 19:02
(Received via mailing list)
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!
This topic is locked and can not be replied to.