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
--
Craig White <craig-CnJ8jr4MGtxl57MIdRCFDg@public.gmane.org>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---