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!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs