I have 3 models... facility - has_many :placements, has_many :client_slots placement - belongs_to :facility, has_one :client_slots client_slot - belongs_to :placements, has_one :facility
My problem is that I want a select list of client_slots based upon facility_id which I get from the below code, but if the placement has a 'client_slot' already, it doesn't indicate it on the form. I want it to show the existing value and to offer choices based upon the facility_id too...
on a placement form...
<%= options = [['Select a Facility', '']] + @facility.sort { |a,b| a.name <=> b.name }.collect { >fac> [fac.name, fac.id] } select 'placement', 'facility_id', options %>
<%= select_tag 'placement', 'client_slot_id', { :disabled => 'disabled' } %></span> <%= observe_field( :placement_facility_id, :update => :client_slot_id, :url => { :controller => 'placements', :action => :lookup_client_slot }, :with => "'facility_id='+escape(value)") %>
and in controller def lookup_client_slot @client_slots = ClientSlot.find(:all, :conditions => ["facility_id = ?", params[:facility_id]] ).collect {|fac| [fac.name, fac.id]} render :inline => "<%= select 'placement', 'client_slot_id', @client_slots %>" end