# Dropdown

**URL:** <https://www.ruby-forum.com/t/dropdown/95527>\
**Category:** Rails\
**Created:** [June 5, 2006, 1:11pm UTC](https://www.ruby-forum.com/t/dropdown/95527 "2006-06-05T13:11:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregnewman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a9a28c/32.png) [@gregnewman](https://www.ruby-forum.com/u/gregnewman)\
**Post date:** [June 5, 2006, 1:11pm UTC](https://www.ruby-forum.com/t/dropdown/95527/1 "2006-06-05T13:11:47Z")

</div>

I’m using a dropdown on my form for a simple cms which displays the  
pages from the database. I want to add some options to the dropdown  
that are not in the database. Is there a way to do this?

Here’s my code so far:

Link  
\<%= select("navigation", "link", Page.find\_all.collect {|p| [p.title, p.id] }) %\>

What I want is to add in a link called “listings” that is not in the  
table as well as a link called “home”. I’m giving the user the option  
to choose the display order, so it doesn’t matter where they show in the  
dropdown. However, it would be nice to have it still autoselect the  
appropriate item in the edit form.

---

<div class="post-metadata">

**Author:** ![gregnewman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a9a28c/32.png) [@gregnewman](https://www.ruby-forum.com/u/gregnewman)\
**Post date:** [June 5, 2006, 1:19pm UTC](https://www.ruby-forum.com/t/dropdown/95527/2 "2006-06-05T13:19:56Z")

</div>

try something like this:

 Home \<%= option\_groups\_from\_collection\_for\_select Page.find\_all, 'id', 'title' %\>

See:

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

for more details.

Hope that helps,

Steve

Greg N. wrote:

> I’m using a dropdown on my form for a simple cms which displays the  
> pages from the database. I want to add some options to the dropdown  
> that are not in the database. Is there a way to do this?
> 
> Here’s my code so far:
> 
> Link  
> \<%= select("navigation", "link", Page.find\_all.collect {|p| [p.title, p.id] }) %\>
> 
> What I want is to add in a link called “listings” that is not in the  
> table as well as a link called “home”. I’m giving the user the option  
> to choose the display order, so it doesn’t matter where they show in the  
> dropdown. However, it would be nice to have it still autoselect the  
> appropriate item in the edit form.

---

<div class="post-metadata">

**Author:** ![gregnewman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a9a28c/32.png) [@gregnewman](https://www.ruby-forum.com/u/gregnewman)\
**Post date:** [June 5, 2006, 2:07pm UTC](https://www.ruby-forum.com/t/dropdown/95527/3 "2006-06-05T14:07:10Z")

</div>

Worked like a charm. Thanks Steve!

Stephen B. wrote:

> try something like this:
> 
> Home \<%= option\_groups\_from\_collection\_for\_select Page.find\_all, 'id', 'title' %\>
> 
> See:  
> [ActionView::Helpers::FormOptionsHelper](http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000404)  
> for more details.
> 
> Hope that helps,
> 
> Steve
