Ruby ajax实现二级联动菜单

 

view页面代码:

 

<label style="font:bold;">Season<span class="required">*</span></label>

<%= select('season', 'id',

      Season.all.collect {|t| [t.name, t.id]}, {:include_blank => true}, 

        {"onchange" => remote_function(

          :with => "'season_id='+value", //传递的参数

          :update => 'series_select', //指定更新的div

          :url => {:controller => :projects, :action => :select_series})})%> 

 

 

<div id="series_select" style="width: 367px;">

</div>

 

controller代码:

 

 def select_series

      @series = Series.find(:all, :conditions => ["season_id = ?", params[:season_id]]).collect { |series| [series.name, series.id] }

      render :partial => "projects/select_series" //用projects/select_series更新 div id="series_select"

    end

 

你可能感兴趣的:(Ajax,Ruby)