# Collection select default value

**URL:** <https://www.ruby-forum.com/t/collection-select-default-value/112465>\
**Category:** Rails\
**Created:** [August 19, 2007, 9:51pm UTC](https://www.ruby-forum.com/t/collection-select-default-value/112465 "2007-08-19T21:51:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanderkerkoff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7feea3/32.png) [@vanderkerkoff](https://www.ruby-forum.com/u/vanderkerkoff)\
**Post date:** [August 19, 2007, 9:51pm UTC](https://www.ruby-forum.com/t/collection-select-default-value/112465/1 "2007-08-19T21:51:04Z")

</div>

Bit of a conundrum, I’m trying to offer a user the opportunity to  
update 3 drop down collection selects at once which is working fine my  
only problem is I can’t seem to get the default value to display, I’ve  
tried using :selected but that doesn’t seem to be working, my code  
looks like:

In the view:

\<%@quals=Qual.find(:all)%\>

\<%for assigned in @degree.assigneds%\>

Grade  
 \<%=text\_field 'assigned'+assigned.id.to\_s, 'grade',"value" =\>assigned.grade %\>

Qualification ID  
\<%=collection\_select('assigned'+assigned.id.to\_s, :qual\_id, @quals,:id, :screen\_qual,{},:selected=\>assigned.qual\_id)%\>  
\<%end%\>

In the controller

@degree.attributes = params[:degree]  
@degree.assigneds.each { |assigned| assigned.attributes =  
params[‘assigned’+assigned.id.to\_s] }  
if @degree.valid? && @degree.assigneds.all?(&:valid?)  
@degree.save!  
@degree.assigneds.each(&:save!)  
redirect\_to :action =\> ‘show’, :id =\> @degree  
else  
render :action =\> ‘edit’  
end

if I change the first variable in the collection select from  
‘assigned’+assigned.id.to\_s to just :assigned then it does work but  
then I can;t work out how to differentiate between the input from each  
of the drop downs in the controller.

Any help would be much appreciated

---

<div class="post-metadata">

**Author:** ![vanderkerkoff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7feea3/32.png) [@vanderkerkoff](https://www.ruby-forum.com/u/vanderkerkoff)\
**Post date:** [August 22, 2007, 11:00pm UTC](https://www.ruby-forum.com/t/collection-select-default-value/112465/2 "2007-08-22T23:00:13Z")

</div>

still having absolutely no luck with this, anyone got any idea?
