# Add items to a select box in \_form.rhtml

**URL:** <https://www.ruby-forum.com/t/add-items-to-a-select-box-in-form-rhtml/89589>\
**Category:** Rails\
**Created:** [March 21, 2007, 12:33pm UTC](https://www.ruby-forum.com/t/add-items-to-a-select-box-in-form-rhtml/89589 "2007-03-21T12:33:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![reg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@reg](https://www.ruby-forum.com/u/reg)\
**Post date:** [March 21, 2007, 12:33pm UTC](https://www.ruby-forum.com/t/add-items-to-a-select-box-in-form-rhtml/89589/1 "2007-03-21T12:33:52Z")

</div>

I have a \_form.rhtml with the following partial

Type  
\<%= select 'account', 'account\_type', 'user' %\>

How can I add other elements i.e. guest, adminstrator to the list in the  
selection box.

Thanks  
Reg

---

<div class="post-metadata">

**Author:** ![reg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@reg](https://www.ruby-forum.com/u/reg)\
**Post date:** [March 21, 2007, 12:53pm UTC](https://www.ruby-forum.com/t/add-items-to-a-select-box-in-form-rhtml/89589/2 "2007-03-21T12:53:34Z")

</div>

> Type  
> \<%= select 'account', 'account\_type', 'user' %\>
> 
> How can I add other elements i.e. guest, adminstrator to the list in the  
> selection box.

\<%= select ‘account’, ‘account\_type’, [[‘user’,'user],  
[‘guest’,'guest],[‘administrator’,'administrator]] %\>

should work. But if you had an AccountTypes model the API docs show  
you a much more elegant way to achieve it:

> **[ActionView::Helpers::FormOptionsHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000506)**
>
> Provides a number of methods for turning different kinds of containers into a set of option tags.

---

<div class="post-metadata">

**Author:** ![reg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@reg](https://www.ruby-forum.com/u/reg)\
**Post date:** [March 21, 2007, 1:07pm UTC](https://www.ruby-forum.com/t/add-items-to-a-select-box-in-form-rhtml/89589/3 "2007-03-21T13:07:24Z")

</div>

glenn wrote:

> > Type  
> > \<%= select 'account', 'account\_type', 'user' %\>
> > 
> > How can I add other elements i.e. guest, adminstrator to the list in the  
> > selection box.
> 
> \<%= select ‘account’, ‘account\_type’, [[‘user’,'user],  
> [‘guest’,'guest],[‘administrator’,'administrator]] %\>
> 
> should work. But if you had an AccountTypes model the API docs show  
> you a much more elegant way to achieve it:  
> [ActionView::Helpers::FormOptionsHelper](http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000506)

Thanks,

I finally figured out a way to do it:

Type  
\<%= select 'account', 'account\_type', ( [['user'], ['administrator']] ) %\>

but thanks for the showing me this option and for the link.

Reg
