check_box_tag框在页面刷新后第一次尝试时不会在params中发送

时间:2016-05-22 20:19:34

标签: ruby-on-rails form-for

我有一个带有包含form_for的页面的rails应用程序。在表单中有一个表,其中包含一系列行,如下所示:

<tr>
  <td><%= u.email %></td>
  <td class="action"><%= check_box_tag "contactlist[]", u.id, false, {onclick:"check()", class:"emailrow"} %></td>
</tr>

表单的submit_tag按钮转到控制器方法。如果我插入&#34; put params&#34;进入控制器方法的第一行,我看到如下:

parameters: {"utf8"=>"✓", "authenticity_token"=>"PgjBBtPoMk2tBbJ5soWpP7kHyNFqA+4p//B2IE0ta/OFnpY0u8To4wFg0PUiuGq81Yu+f2+Lxm9KutrRXOp7wg==", "delete"=>"Delete Selected", "contactlist"=>["77"], "method"=>"post"}

但是,我第一次尝试在页面刷新后提交表单时,没有&#34;联系人列表&#34;尽管选中了复选框,但仍在参数中。如果我在提交失败后重新检查复选框,那么&#34;联系人列表&#34;部分然后出现。

使用rails 4.2.6和ruby 2.2.3p173

编辑:完整表单信息:

 <%= form_for :topics, :url => {:action => "topics_act", :method => "post"} do %>
<%= text_field :query, nil, :placeholder => "Enter term(s)", :id => "newtopic", :size => 20 %>
 <%= submit_tag "Add Topic", 'data-disable-with' => "Processing", name:"add_topic" %>
<%= submit_tag "Save Selected", 'data-disable-with' => "Processing", name:'save' %>
  <%= submit_tag "Delete Selected", 'data-disable-with' => "Processing", name:'delete' %>
<td class="action"><%= check_box_tag "itemlist[]", item.id %></td>
<% end %>

1 个答案:

答案 0 :(得分:1)

如果有人偶然发现这个问题,那么问题就在于Rails 4中的turbolinks。把数据放在没有turbolink =&#34; true&#34;在body标签内修复了问题