title: Rails javascript only works after reload
body: <p>The problem is exactly what the heading says. The javaScript is in the asset pipeline i.e assets/javascripts/myfile.js.coffee In the application.js I have:</p>
  
  <pre><code>//= require jquery
  //= require jquery_ujs
  //= require turbolinks
  //= require jquery.ui.all
  //= requier twitter/bootstrap
  //= require jasny-bootstrap
  //= require_tree .
  </code></pre>
  
  <p>This is the coffeescript</p>
  
  <pre><code>$(document).ready -&gt;
    $("#close").click -&gt;
      $(this).parent().parent().slideUp("slow")
  
  
  
  
    $( "#datepicker" ).datepicker
      dateFormat : "yy-mm-dd"
  
  
    player_count = $("#player option").length
  
  
    $('#btn-add').click -&gt;
      $('#users option:selected').each -&gt;
        if player_count &gt;= 8
          $('#select-reserve').append("&lt;option      value='"+$(this).val()+"'&gt;"+$(this).text()+"&lt;/option&gt;")
          $(this).remove()    
        else
          $('#player').append("&lt;option value='"+$(this).val()+"'&gt;"+$(this).text()+"&lt;/option&gt;")
          $(this).remove()
          player_count++
  
  
    $('#btn-remove').click -&gt;
      $('#player option:selected').each -&gt;
        $('#users').append("&lt;option value='"+$(this).val()+"'&gt;"+$(this).text()+"&lt;/option&gt;")
        $(this).remove()
        player_count--
  
  
    $('#btn-remove-reserve').click -&gt;
      $('#select-reserve option:selected').each -&gt;
        $('#users').append("&lt;option value='"+$(this).val()+"'&gt;"+$(this).text()+"&lt;/option&gt;")
        $(this).remove()
  
  
    $("#submit").click -&gt;
     $("select option").prop("selected", "selected")
  </code></pre>
  
  <p>I can see in the source code on the browser that the javaScript has been loaded, but it only works after I reload the page.</p>