Forum: Ruby on Rails ajax and dependent select lists

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.
64ccb2818312b9be37aac53822425a91?d=identicon&s=25 tom (Guest)
on 2007-06-22 16:34
Have been searching for a solution to this problem for a few weeks and
have had no luck.  I'm sure its a newbie mistake, but can't figure out
how to solve it.

My problem is that I have several dependent select lists that need to be
populated from a database.  The selected items then need to be saved
back to the database. This is a medical application and basically, the
user selects a cancer site in the top level select list which then
generates a list of site-specific tumor stages based on the top level
select.  I can make the dynamically created select list, but can't save
the data from the form.  The code snippet I'm posting doesn't do exactly
that.  It just tries to print the selected item from the dynamically
created list.  I'm including the relevant parts of the views and

Thanks for your help.

def new
   params[:user_id] = "1"
   params[:patient_id] = "1"
   @cancer_sites = MedicalTerm.find_all_by_semantic_class("cancer type")
   @t_stages = ""
   @primary_tumor =

  def provide_t_stage
    unless params[:primary_tumor_tumor_site].blank?
    @t_stages = MedicalTerm.find_all_by_semantic_features("[tumor
classification][#{params[:primary_tumor_tumor_site]}][t stage]")
             render :partial=>'provide_t_stage',
           :locals => {:t_stages => @t_stages}

  def t_stage_selected
    render :partial => 't_stage_selected',
           :locals => {:t_stage_selected =>

<h1>Create Primary Tumor</h1>

<% form_for :primary_tumor do |form| %>

<p><label for="primary_tumor_site">Tumor site</label><br/>
<%= collection_select :primary_tumor, :tumor_site, @cancer_sites, :name,
:name %>
<div id="t_stage">
<%= "??" %>

<div id="t_stage_selected">
  <%= "??" %>

<%= observe_field 'primary_tumor_tumor_site',
                  :update => 't_stage',
                  :url => {:action => 'provide_t_stage', :only_path =>
                  :with => "'primary_tumor_tumor_site=' +
encodeURIComponent(value)" %>

<%= observe_field 'primary_tumor_t_stage',
                  :update => 't_stage_selected',
                  :url => {:action => 't_stage_selected', :only_path =>
                  :with => "'primary_tumor_t_stage=' +
encodeURIComponent(value)" %>

<%= link_to 'Create', :url => {:action => 'create'} %>
<% end %>

<%= link_to 'Show', :action => 'show', :id => @primary_tumor %>

<p><label for="primary_tumor_t_stage">T stage</label><br/>
<%= collection_select :primary_tumor, :t_stage, @t_stages, :name, :name

<%= @t_stage_selected %>
This topic is locked and can not be replied to.