Forum: Ruby on Rails related drop list

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3dca01854f6334f5db0fd6759e3f5c12?d=identicon&s=25 Viva Yang (viva_yang)
on 2009-01-04 04:26
1. new.rhtml

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

<p>


<%=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 } ) }

)%>
<div id='next_select'>
<%= render(:partial => "test") %>
</div>

...


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


3. _test.rhtml

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


Now the second drop list is not working correct.
This topic is locked and can not be replied to.