I have a simple Rails scaffolded application, and would like to add a bunch of JavaScript files (including a special version of JQuery) to support new client-side features.
I added the *.js files to public/javascripts and added <%= javascript_include_tag :all %> at the top of the new.html.erb where they are needed.
PROBLEM: When I first call $(document).ready(function(){ in this ERB, I get Uncaught TypeError: Object #<HTMLDocument> has no method 'ready', which seems to mean that my JQuery library has in fact not been loaded.
You probably want to be loading your javascript in the
<head>section of your HTML instead, to make sure it gets loaded at the proper time. When you put it in yournew.html.erbfile, it’s getting loaded in the body instead.Find you layout, by default
app/views/layouts/application.html.erb, and put it in there in the<head>section instead. This will then be applied to yournew.html.erbpage.