# Using collection\_select for a dropdown list navigation?

**URL:** <https://www.ruby-forum.com/t/using-collection-select-for-a-dropdown-list-navigation/115201>\
**Category:** Rails\
**Created:** [September 21, 2007, 5:36pm UTC](https://www.ruby-forum.com/t/using-collection-select-for-a-dropdown-list-navigation/115201 "2007-09-21T17:36:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![superwick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@superwick](https://www.ruby-forum.com/u/superwick)\
**Post date:** [September 21, 2007, 5:36pm UTC](https://www.ruby-forum.com/t/using-collection-select-for-a-dropdown-list-navigation/115201/1 "2007-09-21T17:36:15Z")

</div>

I’m trying to figure out the best way to do this:  
I have an Artist model  
I want to create a dropdown list of all the artists in the database.  
When you select one of them form the list, you get redirected to their  
respective “show” action.

In my routes.rb (using REST)  
map.resources :artists

In my controller:  
@artists = Artist.find(:all, :order =\> “name”)

In my view:  
\<% form\_for(:artist, :url =\> artist\_path(@artist), :html =\> {:method  
=\> :get}) do |f| %\>  
\<%= f.collection\_select(‘id’, @artists, ‘id’, ‘name’) %\>  
\<%= submit\_tag “go!” %\>  
\<% end %\>

now, of course, this doesn’t work. When submitted, you just get sent  
to the first @artist.id “show” action. I’ve been racking my brain  
trying to figure out how to do this in Rails.

Any help? Thanks much!

-Chad

---

<div class="post-metadata">

**Author:** ![superwick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@superwick](https://www.ruby-forum.com/u/superwick)\
**Post date:** [September 21, 2007, 8:21pm UTC](https://www.ruby-forum.com/t/using-collection-select-for-a-dropdown-list-navigation/115201/2 "2007-09-21T20:21:39Z")

</div>

Basically what I’m trying to do is the Ruby/Rails equivalent of this:

 Choose a destination... Artist 1 Artist 2 Artist 3 Artist 4 Artist 5 Artist 6 Artist 7 Artist 8

Here’s what I’ve come up with:  
\<% form\_tag( “…/”) do %\>  
\<%= collection\_select(:artists, ‘id’, @artists, ‘id’, ‘name’, {},  
{:onchange =\> “window.open(‘[http://0.0.0.0:3000/artists/](http://0.0.0.0:3000/artists/)’ +  
this.options[this.selectedIndex].value,‘\_top’)”}) %\>  
\<% end %\>

This works, I’m just not sure if it’s the best way. Anyone have any  
suggestions?
