title: Can I call a Javascript function from a coffeescript file?
body: <p>I'm trying to call a javascript function from a Coffeescript file, for my <code>$(document).ready()</code> and it's never getting called.</p>
  
  <p>The function I want to call comes from an external source that I have included in my html head element, just before the include of my coffeescript file, like this:</p>
  
  <pre><code>&lt;script src="external.js"&gt;&lt;/script&gt;
  &lt;%= javascript_include_tag params[:controller], 'data-turbolinks-track' =&gt; true %&gt;
  </code></pre>
  
  <p>and in my coffeescript file (called someControllerName.coffee) I do this:</p>
  
  <pre><code>ready = -&gt;
    ... call my method
  
  $ -&gt; ready
  </code></pre>
  
  <p>Is this the correct way? I can see in Chrome that my script is compile to javascript, and I can see it in the Network tab of the inspector.</p>
  
  <p>I'm using Rails 4, and this is my application.js</p>
  
  <pre><code>//= require jquery
  //= require jquery.turbolinks
  //= require jquery_ujs
  //= require bootstrap
  //= require turbolinks
  //= require_tree .
  </code></pre>
  
  <p>edit:</p>
  
  <p>If I replace my method call by <code>alert("...");</code> it works, and if I call my javascript method using javascript in <code>$(document).ready()</code> it works fine.</p>
  
  <p>edit2:</p>
  
  <p>Here's my real javascript function:</p>
  
  <pre><code>var ready = function () {
    $('pre code').each(function (i, e) {
        hljs.highlightBlock(e)
    });
  };
  
  $(document).ready(ready);
  </code></pre>
  
  <p><strong>I solved the problem doing this:</strong></p>
  
  <pre><code>highlight = -&gt;
    $("pre code").each (i, e) -&gt;
      hljs.highlightBlock(e)
  
  $(document).on 'ready page:load', -&gt;
    highlight()
  </code></pre>