Ajax and dependent select lists

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
controller.

Thanks for your help.

primary_tumor_controller.rb
def new
params[:user_id] = “1”
params[:patient_id] = “1”
@cancer_sites = MedicalTerm.find_all_by_semantic_class(“cancer type”)
@t_stages = “”
@primary_tumor = PrimaryTumor.new
end

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}
end
end

def t_stage_selected
render :partial => ‘t_stage_selected’,
:locals => {:t_stage_selected =>
params[:primary_tumor_t_stage]}
end

new.rhtml

Create Primary Tumor

<% form_for :primary_tumor do |form| %>

Tumor site
<%= collection_select :primary_tumor, :tumor_site, @cancer_sites, :name, :name %>

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

<%= observe_field ‘primary_tumor_t_stage’,
:update => ‘t_stage_selected’,
:url => {:action => ‘t_stage_selected’, :only_path =>
false},
:with => “‘primary_tumor_t_stage=’ +
encodeURIComponent(value)” %>

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

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

_provide_t_stage.rhtml

T stage
<%= collection_select :primary_tumor, :t_stage, @t_stages, :name, :name %>

_t_stage_selected.rhtml
<%= @t_stage_selected %>