title: keeping checkbox status in rails
body: <p>I have some  check-boxes in my rails application the code is below </p>
  
  <pre><code>&lt;%= check_box_tag "audio_ids[]",audio.id ,nil,class: "song"%&gt;
  &lt;%= check_box_tag "audio_ids[]",audio.id ,nil,class: "song"%&gt;
  &lt;%= check_box_tag "audio_ids[]",audio.id ,nil,class: "song"%&gt;
  &lt;button class="btn btn-warning"&gt;play all&lt;/button&gt;
  
  &lt;script&gt;
  function handleButtonClick(button){
  if ($(button).text().match("Check all")){
  $(":checkbox").prop("checked", true)
  } else {
  $(":checkbox").prop("checked", false)
  };
  updateButtonStatus();
  }
  
  function updateButtonStatus(){
  var allChecked = $(":checkbox").length === $(":checkbox:checked").length;
  $("button").text(allChecked? "Uncheck all" : "Check all");
  }
  
  function updateCookie(){
  var elementValues = {};
  $(":checkbox").each(function(){
  elementValues[this.id] = this.checked;
  });
  
  elementValues["buttonText"] = $("button").text();
  $.cookie('elementValues', elementValues, { expires: 7, path: '/' })
  }
  
  function repopulateFormELements(){
  var elementValues = $.cookie('elementValues');
  if(elementValues){
  Object.keys(elementValues).forEach(function(element) {
  var checked = elementValues[element];
  $("#" + element).prop('checked', checked);
  });
  
  $("button").text(elementValues["buttonText"])
  }
  }
  
  $(":checkbox").on("change", function(){
  updateButtonStatus();
  updateCookie();
  });
  
  $("button").on("click", function() {
  handleButtonClick(this);
  updateCookie();
  });
  
  
  $.cookie.json = true;
  repopulateFormELements();
  &lt;/script&gt;
  </code></pre>
  
  <p>They keep their status while just refreshing the page but whenever i came from different page they lost their status but when I check this code separately it works but not with rails , what is the problem with this code and what I have to do?</p>