2012-09-11 77 views
0

我有以下形式(截)無法獲取複選框陣列提交

<%= form_for(daysevent, :html => { :class => "form-inline"}) do |f| %> 
    <fieldset> 
    <div class="control-group"> 
     <%= f.label :start_date, :class => 'control-label' %> 
     <div class="controls"> 
      <%= f.text_field :start_date, 'data-behavior' => 'datepicker1' %> 
     </div> 
     </div> 
     <div class="control-group"> 
     <%= f.label :end_date, :class => 'control-label' %> 
     <div class="controls"> 
      <%= f.text_field :end_date, 'data-behavior' => 'datepicker2' %> 
     </div> 
     </div> 
    Locations for this date:<br/> 
    <% daysevent.event.locations.each do |l|%>   
     <%= check_box_tag 'location_ids[]', l.id, true -%><%= h l.name -%><br/>  
    <% end %> 
    <%= f.submit 'Create Date' %> 
    </fieldset> 
    <% end %> 

我試圖讓位置複選框的列表中ID數組來通過,但它不工作,在我的create方法返回render:text => params [:days_event]剛剛返回start_date和end_date。我只做了幾個月的軌道,所以它可能很簡單,但都有助於他的讚賞。

回答

1

您不發送params[:days_event]中的複選框值,而是發送params[:locations_ids]。你可以檢查rails server的調試輸出,你會看到解析params散列。

如果你想一起發送它們然後更改複選框:

<%= check_box_tag "days_event[location_ids][]" .... %>