I have a rails view like this:
<%= javascript_include_tag "my_js" %> <%# foo function is defined here %>
<div>
<%# stuff %>
</div>
<script>
var ready;
ready = function() { foo(); }
$(document).ready(ready);
$(document).on('page:load', ready);
</script>
And when I load this page, I have this error:
Uncaught ReferenceError: foo is not defined
However, when I refresh the page, everything works fine.
What I find really strange is that, even if I access the page multiple times using only the links on my site, the error will pop every time. I really have to use a refresh for the script to load!
What could be the cause of this?