# Collection\_select

**URL:** <https://www.ruby-forum.com/t/collection-select/135098>\
**Category:** Rails\
**Created:** [April 17, 2008, 9:23pm UTC](https://www.ruby-forum.com/t/collection-select/135098 "2008-04-17T21:23:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [April 17, 2008, 9:23pm UTC](https://www.ruby-forum.com/t/collection-select/135098/1 "2008-04-17T21:23:51Z")

</div>

I have posted before about collection\_select but have not gotten what I  
am working on to work. I have even searched the archives for similar  
discussions and am at a little bit of a loss because some have claimed  
to have fixed the problem but I still can’t get it to work for me.

What I am trying to do is simply add the :selected option to the  
collection\_select helper. This is what I got:

\<%= collection\_select(“user”, “w\_country” , Countrycode.find( :all,  
:order =\>  
‘country’ ), :id, :country, :selected =\> 159573, :onchange =\> func )  
%\>

I simply want it to select the country code that has the specified id.  
The onchange is for when a selection is made the drop down reverts back  
to a link on a form. Has anyone gotten the combination of these two to  
work? Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [April 18, 2008, 3:00am UTC](https://www.ruby-forum.com/t/collection-select/135098/2 "2008-04-18T03:00:49Z")

</div>

On Fri, Apr 18, 2008 at 5:23 AM, Shandy N.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= collection\_select(“user”, “w\_country” , Countrycode.find( :all,  
> :order =\>  
> ‘country’ ), :id, :country, :selected =\> 159573, :onchange =\> func )  
> %\>

I had something similar.

What I ended up doing is manually coding the select tag, and then  
adding an ‘options for select’ tag underneath within the manual select  
tag.

Works fine.

Remember, the helper methods are there to help, but if they get in the  
way, don’t be afraid to get rid of them - or make a new one that does  
exactly what you want.

Mikel
