# Frustrrated - Simple Drop Down

**URL:** <https://www.ruby-forum.com/t/frustrrated-simple-drop-down/135665>\
**Category:** Rails\
**Created:** [April 24, 2008, 12:31am UTC](https://www.ruby-forum.com/t/frustrrated-simple-drop-down/135665 "2008-04-24T00:31:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rushnosh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58956e/32.png) [@rushnosh](https://www.ruby-forum.com/u/rushnosh)\
**Post date:** [April 24, 2008, 12:31am UTC](https://www.ruby-forum.com/t/frustrrated-simple-drop-down/135665/1 "2008-04-24T00:31:16Z")

</div>

i have an array  
@item = [[name1, value1] [name2, value2] [name3, value4] ] which  
comes from the controller

i want to put this into a drop down menu where the item chosen goes  
to :enter\_by

i also need to go back to the same form

where the same array @item is displayed but this time the item  
selected ( :enter\_by ) is now selected.

i don’t want to use ajax

i have read and re-read, and then made a trip to the bookstore about  
select, select\_tag, options\_for\_select  
i going on 3 hours sleep in 48 hours and need this badly.

this can not be soooooo complicated.

i can get the items to display, i can return the item selected but i  
can not get the selected item to show if i go back to the form.

---

<div class="post-metadata">

**Author:** ![rushnosh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58956e/32.png) [@rushnosh](https://www.ruby-forum.com/u/rushnosh)\
**Post date:** [April 24, 2008, 12:38am UTC](https://www.ruby-forum.com/t/frustrrated-simple-drop-down/135665/2 "2008-04-24T00:38:28Z")

</div>

hi rushnosh, i’m back (with a bit more time now)

i posted what you wanted (as far as i understood you) in your last  
question. select which sets the selected items for a multiple select  
box.  
could you have a look at it and maybe tell me, what you don’t understand  
or what does not fit with your request?

the only difference is, that in my example the array is hardcoded, but  
you can replace it with any array you want.

---

<div class="post-metadata">

**Author:** ![rushnosh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58956e/32.png) [@rushnosh](https://www.ruby-forum.com/u/rushnosh)\
**Post date:** [April 24, 2008, 1:00am UTC](https://www.ruby-forum.com/t/frustrrated-simple-drop-down/135665/3 "2008-04-24T01:00:01Z")

</div>

ok, just typed that in:

in your controller:  
@items = [[‘A’,1], [‘B’, 2], [‘C’, 3], [‘D’, 4], [‘E’, 5]]

this should’ve been returned (i simulate it):  
params[:enter\_by] = 2

in your view:  
\<%= select\_tag(“enter\_by”, options\_for\_select(@items,  
params[:enter\_by])) %\>

where options\_for\_select gets two items:  
the array with the options  
the selected item

it should make no difference, if you render this the simple way or  
replace it with ajax

---

<div class="post-metadata">

**Author:** ![rushnosh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58956e/32.png) [@rushnosh](https://www.ruby-forum.com/u/rushnosh)\
**Post date:** [April 24, 2008, 2:40am UTC](https://www.ruby-forum.com/t/frustrrated-simple-drop-down/135665/4 "2008-04-24T02:40:30Z")

</div>

i did look at your code and tested. it was not for a drop down.  
i finally, finally got it to work - but i can not believe this how  
ruby does it. it is extremely ugly. i know it can be done in a cleaner  
fashion with ajax/rjs but i didn’t want to add another level of  
difficulty to it.

the help came from this post  
\<[Building a Better Drop Down Selection List for Ruby on Rails – False Positives](http://www.falsepositives.com/index.php/2005/12/10/building-a-better-)  
drop-down-selection-list-for-ruby-on-rails/\>

now i have to repeat this code about 100 times and i am dreading it.  
almost 2 days to figure this out.

PLEASE, PLEASE let me know if there is a better way to do, there has  
to be, unless folks just don’t use drop down menus/selections anymore.  
until now i was so gunho about ruby.

On Apr 23, 3:38 pm, Thorsten M. \<rails-mailing-l…@andreas-
