Related drop list

  1. new.rhtml

New pr_cate

<%= javascript_include_tag 'prototype' %> <% form_for(@pr_cate) do |f| %> <%= f.error_messages %>

<%=f.select(:id, @pr_cates.map {|u| [u.name,u.id]},
{:onchange => remote_function(
:with => “‘id=’+value”,
:method => “get”,
:update => ‘next_select’,
:url => { :action => :new } ) }

)%>

<%= render(:partial => "test") %>

  1. controller

def new

if params[:id]
@pr_cates = PrCate.find(:all, :conditions => [“parent_id = ?”,
params[:id]])
else
@pr_cates = PrCate.find(:all, :conditions => [“parent_id = ?”, “0”])
end

@pr_cate = PrCate.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @pr_cate }
end
end

  1. _test.rhtml

<%= select(“pr_cate”,“id”, @pr_cates.map {|u| [u.name,u.id]}) %>

Now the second drop list is not working correct.