This works except for one thing...if there''s a value in
placement.client_slot_id, it doesn''t ''select'' the
value in the selection
list. How can I get it to select the value that matches
@placement.client_slot_id.name ?
view
<span id="client_slot_id">
<%= select_tag ''placement'',
''client_slot_id'',
:selected => @placement.client_slot.name %></span>
<%= observe_field(
:placement_facility_id,
:frequency => 0.5,
:update => :client_slot_id,
:url => { :controller => ''placements'',
:action => :lookup_client_slot },
:with => "''facility_id=''+escape(value)")
%>
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
-~----------~----~----~----~------~----~------~--~---
Craig White wrote:> <%= select_tag ''placement'', ''client_slot_id'', > :selected => @placement.client_slot.name %></span>According to the docs, select_tag takes the object and a string containing the actual text <option>blah</option>. http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#M000494 You may want to look at collection_select instead. http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000400 Alan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Wed, 2006-12-20 at 10:57 +0100, Alan Francis wrote:> Craig White wrote: > > > <%= select_tag ''placement'', ''client_slot_id'', > > :selected => @placement.client_slot.name %></span> > > According to the docs, select_tag takes the object and a string > containing the actual text <option>blah</option>. > http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#M000494 > > You may want to look at collection_select instead. > http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000400 >---- I promise that I wouldn''t have posted my question if I hadn''t gone over and over these api pages and still clanking my head against the wall. I have used options and collections in quite a few different areas of this web application but never in this manner. The issue that I am having is that I am able to return the proper selection list via controller code rendered inline but no matter what I try, I can''t get it to match up the current value as the ''selected'' item in the selection list itself. I do notice though, that by having my view code like this... <span id="client_slot"> <%= select_tag(''placement'', ''client_slot_id'', options = {:selected => @placement.client_slot_id}) %></span> that it results in queer html... <span id="client_slot"> <select id="placement" name="placement" selected="106">client_slot_id</select></span> because both the select id and name are placement whereas view code... <%= options = [["Accepted?", "" ]] + ApplicationHelper::YES_NO select("placement", "accepted", options) %> results in... <select id="placement_accepted" name="placement[accepted]"> <option value="">Accepted?</option> <option value="true" selected="selected">Yes</option> <option value="false">No</option></select> Craig -- 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 -~----------~----~----~----~------~----~------~--~---