# Non-database dropdown select - works fine, but why the weird order?

**URL:** <https://www.ruby-forum.com/t/non-database-dropdown-select-works-fine-but-why-the-weird-order/149410>\
**Category:** Rails\
**Created:** [September 24, 2008, 3:44pm UTC](https://www.ruby-forum.com/t/non-database-dropdown-select-works-fine-but-why-the-weird-order/149410 "2008-09-24T15:44:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 24, 2008, 3:44pm UTC](https://www.ruby-forum.com/t/non-database-dropdown-select-works-fine-but-why-the-weird-order/149410/1 "2008-09-24T15:44:03Z")

</div>

I have built a select\_tag dropdown to represent a group of selections  
that will feed a model-query routine I’ve written.  
This routine works fine but the order of the items is different than  
what I programmed. My objection to this order is that I want the ‘All  
=\> ‘’’ to be on the top.  
Here it is;

```
    <tr>
      <td><strong><%= "User Module" %></strong></td>
      <td> <%= select_tag(:module, options_for_select('All' =>

```

‘’, ‘Evidence’ =\> 1, ‘Assets’ =\> 2, ‘Inventory’ =\> 3, ‘Water’ =\> 4,  
‘Laboratory’ =\> 5, ‘State EPA’ =\> 6, ‘Administrator’ =\> 7), :style =\>  
“width:206px”, :id =\> :indexselect) %\>

and here is the order of items as they ‘drop down’ on the form.

Laboratory  
All  
Administrator  
Assets  
Water  
Evidence  
Inventory  
State EPA

I am grateful for any suggestions.  
Kathleen

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 24, 2008, 3:47pm UTC](https://www.ruby-forum.com/t/non-database-dropdown-select-works-fine-but-why-the-weird-order/149410/2 "2008-09-24T15:47:35Z")

</div>

Hashes in Ruby do not keep the insertion order, you should do it like  
this:

\<%= select\_tag :module, options\_for\_select( [[‘All’,‘’], [‘Evidence’  
, 1], [‘Assets’, 2], [‘Inventory’, 3], [‘Water’ , 4], [‘Laboratory’ ,  
5], [‘State EPA’, 6], [‘Administrator’, 7]]), :style =\> “width:206px”,  
:id =\> :indexselect %\>

On Wed, Sep 24, 2008 at 10:41 AM, removed\_email\_address@domain.invalid  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> <td> <%= select_tag(:module, options_for_select('All' =>
> 
> ```
> 
> Assets  
> Water  
> Evidence  
> Inventory  
> State EPA
> 
> I am grateful for any suggestions.  
> Kathleen
> 
> >

–  
Maurício Linhares  
[http://alinhavado.wordpress.com/](http://alinhavado.wordpress.com/) (pt-br) | [http://blog.codevader.com/](http://blog.codevader.com/)  
(en)  
João Pessoa, PB, +55 83 8867-7208
