Note that there are some explanatory texts on larger screens.

plurals
  1. PONew Rails 3.2.8 app not loading jQuery
    text
    copied!<p>I did a <code>rails new</code> today, then created a simple search bar:</p> <pre><code>&lt;form&gt; &lt;input id='search-bar' type='search' name='search'&gt;&lt;/input&gt; &lt;/form&gt; &lt;a id='search-btn' href="#"&gt;searching!&lt;/a&gt; </code></pre> <p>Alright, how about some click handlers! So assets/javascripts/searches.js.coffee:</p> <pre><code>$('#search-btn').click -&gt; alert 'BOOM' query = $('#search-bar').html console.log query </code></pre> <p>And... nothing. So I go to the Chrome console:</p> <pre><code>&gt;$('a') null &gt;$('body') null &gt;$ function () { [native code] } </code></pre> <p>a jQuery with no selectors, not too helpful. What is going on here? If I add <code>&lt;script type="text/javascript" src='http://code.jquery.com/jquery-1.8.2.js'&gt;&lt;/script&gt;</code> to the page or my layout.html.erb, we're all good.</p> <p>I'm having the same issue with underscore-min.js (note it is not .min.js) not loading despite being in assets/javascripts. Given my (unmodified) application.js, it should load the current folder:</p> <pre><code>//= require jquery //= require jquery_ujs //= require_tree . </code></pre> <p>UPDATE</p> <p>If I go to the Chrome inspector's Resources tab and check out application.js, I see this:</p> <pre><code>// This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // the compiled file. // // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD // GO AFTER THE REQUIRES BELOW. // //= require jquery //= require jquery_ujs //= require_tree . ; </code></pre> <p>That doesn't look like it is properly including the js files inside its directory</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload