简体   繁体   English

使用kaminari分页在Rails上的ruby中选择复选框传递数组

[英]Select checkbox pass array in ruby on rails using kaminari pagination

I have my view where I am showing all the records and I need to add a checkbox for multiple selection, I am doing it in the following way: 我有显示所有记录的视图,并且需要添加一个复选框以进行多项选择,我通过以下方式进行操作:

<%= form_tag("/user_selection", method: 'get', remote: true, class: "form-horizontal" ) do %><!--responde al index-->

  <div class="rwd">
    <table class="table table-striped table-bordered table-condensed table-hover">
      <thead>
        <tr>
          <th>name</th>
          <th>last name</th>
        </tr>
      </thead>
      <tbody id="container_users">
          <%= render @users %>

      </tbody>
    </table>
    <%= paginate @users, :param_name => 'users' %>

  </div>
  <%= submit_tag "send", data: { disable_with: 'sending...' } %>
<% end %>

partial user 部分用户

<tr id="user_<%= user.Id %>">
  <td><%=user.try(:name)%></td>
  <td><%=user.try(:lastname)%></td>
  <td><%= check_box_tag "items[]", user.Id %></td>
</tr>

This way I can select multiple records and send the ids to the controller, the problem comes when I select the records and I go to the next page using the page of kaminari, when passing from page the records of the previous page are no longer selected, like could you solve it? 这样,我可以选择多个记录并将ID发送给控制器,当我选择记录并使用kaminari页面转到下一页时出现问题,当从该页面传递时不再选择上一页的记录,您能解决吗?

1). 1)。 Save all selected users to form's hidden field selected_user_ids . 将所有选定的用户保存到表单的隐藏字段selected_user_ids Kaminari should send remote request and update only user's table but not whole page. Kaminari应该发送远程请求并仅更新用户表,而不更新整个页面。 In this case selected_user_ids will keep all seleted users. 在这种情况下, selected_user_ids将保留所有selected_user_ids用户。

Second way: Save all selected users to localStorage. 第二种方式:将所有选定的用户保存到localStorage。 On form submit extract all users ids from localStorage and save them when to hidden field and send form. 在表单上提交时,从localStorage中提取所有用户ID,并将它们保存到隐藏字段中并发送表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM