Dropdown

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.

try something like this:

Home <%= option_groups_from_collection_for_select Page.find_all, 'id', 'title' %>

See:

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.

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
for more details.

Hope that helps,

Steve