# Problem with select\_tag

**URL:** <https://www.ruby-forum.com/t/problem-with-select-tag/78719>\
**Category:** Rails\
**Created:** [December 8, 2006, 12:25am UTC](https://www.ruby-forum.com/t/problem-with-select-tag/78719 "2006-12-08T00:25:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![richard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](https://www.ruby-forum.com/u/richard)\
**Post date:** [December 8, 2006, 12:25am UTC](https://www.ruby-forum.com/t/problem-with-select-tag/78719/1 "2006-12-08T00:25:56Z")

</div>

I’m using the following tag in a partial:

\<%= select\_tag options\_from\_collection\_for\_select(@cuisines, “name”,  
“id”) %\>

to create a drop down menu of cuisines. However, the output I’m getting  
it an empty menu.

When I view the source I see the following:

Any ideas as to what is going wrong?

---

<div class="post-metadata">

**Author:** ![richard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](https://www.ruby-forum.com/u/richard)\
**Post date:** [December 8, 2006, 12:45am UTC](https://www.ruby-forum.com/t/problem-with-select-tag/78719/2 "2006-12-08T00:45:28Z")

</div>

On 12/8/06, Richard [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m using the following tag in a partial:
> 
> \<%= select\_tag options\_from\_collection\_for\_select(@cuisines, “name”,  
> “id”) %\>
> 
> to create a drop down menu of cuisines. However, the output I’m getting  
> it an empty menu.

First parameter should be the name of the dropdown with options HTML  
being  
second:

\<%= select\_tag “cuisine\_id”,  
options\_from\_collection\_for\_select(@cuisines,  
“name”, “id”) %\>

---

<div class="post-metadata">

**Author:** ![richard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](https://www.ruby-forum.com/u/richard)\
**Post date:** [December 8, 2006, 12:55am UTC](https://www.ruby-forum.com/t/problem-with-select-tag/78719/3 "2006-12-08T00:55:34Z")

</div>

Maxim K. wrote:

> On 12/8/06, Richard [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I’m using the following tag in a partial:
> > 
> > \<%= select\_tag options\_from\_collection\_for\_select(@cuisines, “name”,  
> > “id”) %\>
> > 
> > to create a drop down menu of cuisines. However, the output I’m getting  
> > it an empty menu.
> 
> First parameter should be the name of the dropdown with options HTML  
> being  
> second:
> 
> \<%= select\_tag “cuisine\_id”,  
> options\_from\_collection\_for\_select(@cuisines,  
> “name”, “id”) %\>

gah, can’t believe I missed that. Thanks! By the way, is there any way  
of having one of the menu options select all cuisines? Or could one of  
the options perhaps send a null value to my action, then I could just  
say if it’s null show all cuisines.

---

<div class="post-metadata">

**Author:** ![richard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](https://www.ruby-forum.com/u/richard)\
**Post date:** [December 8, 2006, 1:23am UTC](https://www.ruby-forum.com/t/problem-with-select-tag/78719/4 "2006-12-08T01:23:31Z")

</div>

You can do something like this:

select\_tag(‘new\_member’,  
options\_for\_select([’’]removed\_email\_address@domain.invalid\_not\_in\_group))

As you see you can add blank (’’) as a new option.

---

<div class="post-metadata">

**Author:** ![richard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](https://www.ruby-forum.com/u/richard)\
**Post date:** [February 26, 2009, 9:04pm UTC](https://www.ruby-forum.com/t/problem-with-select-tag/78719/5 "2009-02-26T21:04:13Z")

</div>

Jinal Jhaveri wrote:

> You can do something like this:
> 
> select\_tag(‘new\_member’,  
> options\_for\_select([’’]removed\_email\_address@domain.invalid\_not\_in\_group))
> 
> As you see you can add blank (’’) as a new option.

perfect dude! I was looking exactly for this
