0

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?

Mat
  • 952
  • 2
  • 11
  • 28
  • Possible duplicate of [Rails 4: how to use $(document).ready() with turbo-links](http://stackoverflow.com/questions/18770517/rails-4-how-to-use-document-ready-with-turbo-links) – Vucko Apr 16 '16 at 14:10
  • Looks like the same problem, but the answer didn't solve it :( – Mat Apr 16 '16 at 14:26
  • Well, I simply removed turbolinks. I don't know why it's there by default. Not everyone has a use for it. – Mat Apr 16 '16 at 14:37

0 Answers0