# Related drop list

**URL:** <https://www.ruby-forum.com/t/related-drop-list/156849>\
**Category:** Rails\
**Created:** [January 4, 2009, 4:26am UTC](https://www.ruby-forum.com/t/related-drop-list/156849 "2009-01-04T04:26:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![viva\_yang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a9adbd/32.png) [@viva\_yang](https://www.ruby-forum.com/u/viva_yang)\
**Post date:** [January 4, 2009, 4:26am UTC](https://www.ruby-forum.com/t/related-drop-list/156849/1 "2009-01-04T04:26:46Z")

</div>

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.
