# How to sort select tag options?

**URL:** <https://www.ruby-forum.com/t/how-to-sort-select-tag-options/160621>\
**Category:** Rails\
**Created:** [February 18, 2009, 7:33am UTC](https://www.ruby-forum.com/t/how-to-sort-select-tag-options/160621 "2009-02-18T07:33:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeba-momin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/8e7dd6/32.png) [@zeba-momin](https://www.ruby-forum.com/u/zeba-momin)\
**Post date:** [February 18, 2009, 7:33am UTC](https://www.ruby-forum.com/t/how-to-sort-select-tag-options/160621/1 "2009-02-18T07:33:10Z")

</div>

Hi,  
I have a select tag as :  
\<%= select(:feedbacks, :directedto , {"----Select  
One----"=\>“none”,“Business contact”=\>“Business Contact”,“Technical  
support”=\>“Technical Support”,“Payment Help”=\>“Payment Help”},{  
:selected =\> “none”},  
{:class=\>“field”, :style=\>“width:192px;”}) %\>

I want the select options in the drop down to appear in the same order  
as I have written them in the code…  
But…this does not happen…and the options appear in any random  
order…!!!  
Can anyone please help me…as to how should I sort my select options…  
Thank you…

---

<div class="post-metadata">

**Author:** ![zeba-momin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/8e7dd6/32.png) [@zeba-momin](https://www.ruby-forum.com/u/zeba-momin)\
**Post date:** [February 18, 2009, 8:34am UTC](https://www.ruby-forum.com/t/how-to-sort-select-tag-options/160621/2 "2009-02-18T08:34:02Z")

</div>

problem is that you are using a hash, which have no guaranteed order.  
try an array like this:

\<%= select(:feedbacks, :directedto, ([["----Select One----",  
“none”], [“Business contact”, “Business Contact”], [“Technical  
support”, “Technical Support”], [“Payment Help”, “Payment Help”]]),  
{:selected =\> “none”}, {:class=\>“field”, :style=\>“width:192px;”}) %\>

---

<div class="post-metadata">

**Author:** ![zeba-momin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/8e7dd6/32.png) [@zeba-momin](https://www.ruby-forum.com/u/zeba-momin)\
**Post date:** [February 18, 2009, 8:42am UTC](https://www.ruby-forum.com/t/how-to-sort-select-tag-options/160621/3 "2009-02-18T08:42:56Z")

</div>

MaD wrote:

> problem is that you are using a hash, which have no guaranteed order.  
> try an array like this:
> 
> \<%= select(:feedbacks, :directedto, ([["----Select One----",  
> “none”], [“Business contact”, “Business Contact”], [“Technical  
> support”, “Technical Support”], [“Payment Help”, “Payment Help”]]),  
> {:selected =\> “none”}, {:class=\>“field”, :style=\>“width:192px;”}) %\>

Thank You so much…  
That did the trick…  
Thanks again…
