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