2012-09-11 81 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][]" .... %>