0

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?

jeff
  • 367
  • 4
  • 19

1 Answers1

1

1). Save all selected users to form's hidden field selected_user_ids. Kaminari should send remote request and update only user's table but not whole page. In this case selected_user_ids will keep all seleted users.

Second way: Save all selected users to localStorage. On form submit extract all users ids from localStorage and save them when to hidden field and send form.

Alex Kojin
  • 5,044
  • 2
  • 29
  • 31