title: Rails: Posting Multiple Checkbox Values To Controller On Change Event
body: <p>I have a paginated table with multiple objects and want to pass their IDs to a session variable depending on if their row's checkbox tag has been selected to store as the user browses across multiple pages before exporting the final list of IDs. It is currently working when I select each row individually, but when I hit the "Select All" checkbox, only the last ID on each page ends up being saved to the session variable</p>
  
  <p>In order to do so, I am passing each ID via a change event:</p>
  
  <p>Javascript:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  $(function(){
      $('#selectall').click(function(i, v){
  $('.css-checkbox').prop('checked', this.checked).trigger("change");
      });
  
  var checkCount = $('.css-checkbox').length;
  $('.css-checkbox').click(function(i, v){
      $('#selectall').prop('checked',$('.css-checkbox:checked').length  == checkCount)
  });
  
  $('.css-checkbox').change(function(){
  $.post('user_exports/update_user_export_session', { object_id:  $(this).val(), checked: this.checked});
      });
  });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Update action in controller:</p>
  
  <pre><code>def update_user_export_session
  
    render :nothing =&gt; true
  
    session[:object_ids] ||= []
  
    if params[:checked] == "true"
        session[:object_ids] &lt;&lt; params[:object_id]
    else
        session[:object_ids].delete(params[:object_id])
    end
  
  end
  </code></pre>
  
  <p>When I click the SelectAll checkbox, the rails server shows 10 parameters getting passed to the update_session method in the controller, but the session[:object_ids] ends up with only one ID.</p>