# How to do sorting in ROR

**URL:** <https://www.ruby-forum.com/t/how-to-do-sorting-in-ror/86316>\
**Category:** Rails\
**Created:** [February 21, 2007, 12:56pm UTC](https://www.ruby-forum.com/t/how-to-do-sorting-in-ror/86316 "2007-02-21T12:56:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [February 21, 2007, 12:56pm UTC](https://www.ruby-forum.com/t/how-to-do-sorting-in-ror/86316/1 "2007-02-21T12:56:33Z")

</div>

hi,

is there any command for sorting the list box items in ROR. if its  
please tell me

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [February 21, 2007, 1:35pm UTC](https://www.ruby-forum.com/t/how-to-do-sorting-in-ror/86316/2 "2007-02-21T13:35:32Z")

</div>

Hi, are the list box items being retrieved from the DB? If so, you  
can simply use the ‘:order’ within the find method of your model. For  
example,

orders = Order.find(:all, :order =\> [“pay\_type, shipped\_at DESC”],  
:conditions =\> “id = ?”, 25 )

If not, please provide more information as to how you’re populating  
the list box.

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [February 21, 2007, 9:58pm UTC](https://www.ruby-forum.com/t/how-to-do-sorting-in-ror/86316/3 "2007-02-21T21:58:09Z")

</div>

Conrad T. wrote:

> Hi, are the list box items being retrieved from the DB? If so, you  
> can simply use the ‘:order’ within the find method of your model. For  
> example,
> 
> orders = Order.find(:all, :order =\> [“pay\_type, shipped\_at DESC”],  
> :conditions =\> “id = ?”, 25 )
> 
> If not, please provide more information as to how you’re populating  
> the list box.
> 
> Good luck,
> 
> -Conrad

You can also sort any array of object by some method or attribute.

orders.sort {|a, b| a.total \<=\> b.total}
