Forum: Ruby on Rails RE: Linking two HTML SELECT's together

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Hogan, Brian P. (Guest)
on 2006-03-20 22:46
(Received via mailing list)
Here's what I did... Very hastily hacked from an existing program:

View page:

<!-- show list of projects in the system -->
<select id="test" name="task[project_id]">
	<%=options_from_collection_for_select(@projects, "id", "name",
params['pid'].to_i )%>

<!-- observe projects list and get the list of assigned team members ->

<%= observe_field("test",
	:update => "output_field",
	:url => {:action => "ajax_project_members"}

<!-- display output here -->
<span id="output_field">
  Select a project.


  def ajax_project_members
    res = ""
    p = Project.find(id, :include=>[:teammembers]) rescue nil
    if p.nil?
        res = 'Choose a project'
    	res += "<select name="task[assigned_to]">
    	res += options_from_collection_for_select p.teammembers, "id",
    	res +="</select>"
    return result


Looking at this now, I notice it could be done a little differently (you
could just use <%select %> instead of options_from_collection... But
this still works. (this was originally for a form that had multiple
tasks that you could move to a different project.)
This topic is locked and can not be replied to.