Hi Everyone,
I have number of select lists in my rails application like this:
<li>Company<span><%= f.select :company_id, Company.all.collect {|m| [m.companyname, m.id]} %></span></li>
They all work well, except - sometimes if you go to the edit view, the select list reverts to the top item, not the item that was chosen when creating. So if you go to an edit view and then click update without actually making any changes, the lists default to the top item - even though you didn't touch them.
Is there a way around this?
Thanks,
Danny
EDIT:
<% form_for (@kase), :html => { :multipart => true } do |f| %>
<li>Appointed Surveyor<span><%= f.select :appointedsurveyor_id, Company.all.collect {|m| [m.companyname, m.id]}, {:selected => @kase.appointedsurveyor_id} %></span></li>
<li>Surveyor Name<span><%= f.select :surveyorperson_id, Person.all.collect { |x| [x.personname, x.id]}, {:selected => @kase.surveyorperson_id} %></span></li>
I have tried the above, but sadly it still seems to revert to the default value.
I'm stuck on this, I can't find any tutorials etc on this at all.
EDIT 2:
<li>Appointed Surveyor<span><%= f.select :appointedsurveyor_id, Company.all.collect {|m| [m.companyname, m.id]}, {:selected => (@kase.appointedsurveyor_id rescue "")} %></span></li>
<li>Surveyor Name<span><%= f.select :surveyorperson_id, Person.all.collect { |x| [x.personname, x.id]}, {:selected => (@kase.surveyorperson_id rescue "")} %></span></li>