# Setting a default value in collection\_select

**URL:** <https://www.ruby-forum.com/t/setting-a-default-value-in-collection-select/116697>\
**Category:** Rails\
**Created:** [October 8, 2007, 8:33pm UTC](https://www.ruby-forum.com/t/setting-a-default-value-in-collection-select/116697 "2007-10-08T20:33:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arif](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/74df32/32.png) [@arif](https://www.ruby-forum.com/u/arif)\
**Post date:** [October 8, 2007, 8:33pm UTC](https://www.ruby-forum.com/t/setting-a-default-value-in-collection-select/116697/1 "2007-10-08T20:33:48Z")

</div>

Hi,  
Could anybody cast some light on these:

1. How can I set a default value in a collection\_select? To be specific,  
I  
have a class ‘Platform’, and I want to set the platform\_code (a field of  
Platform) to be ‘ORA’ (which exists in the Platform table).  
I tried many variations of the following code in my view, but in vain:  
\<% @selected = ‘ORA’ %\>  
\<%= collection\_select “sac\_table\_platform”, “platform\_code”,  
Platform.find(:all, :order =\> “platform\_code”),  
:platform\_code, :platform\_code, { :selected =\> @selected } %\>

2. How can I build my own list of collection\_select, e.g., a list of  
three  
people, say, to show [Adam, Bob, Charley] on the collection\_select for  
the  
corresponding values [‘A’, ‘B’, ‘C’] in a table (which already exists),  
and  
use it in my view?

Thanks,  
Arif

–  
View this message in context:  
[http://www.nabble.com/Setting-a-default-value-in-collection\_select-tf4589956.html#a13102355](http://www.nabble.com/Setting-a-default-value-in-collection_select-tf4589956.html#a13102355)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).
