I have a js file in my assets/javascripts/ directory. This file is being picked up by rails correctly ( I can see it in firebug when I check the page's head tag)
And I'm calling a function from this js file in my application.js as follows:
//
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require_tree .
$(window).load(function(){
Boxlayout.init();
});
I read on SO somewhere that the init() functions must be called with .load function so that they are called after the DOM is loaded.
But here the javascript is not working.
On the contrary when I explicitly include the js file with:
<%= javascript_include_tag "file.js" %>
at the bottom of the page and call the same init function from application.js the javascript works fine.
I don't want to explicitly include the file. ( want to do it the rails way). So how do I do it with the first method?
EDIT
Using Rails 3.2.14 (No Turbolinks).
Also the Javascript is not working on Heroku though it works fine locally.
.load(…)was deprecated in jQuery 1.8; you should be using.on("load", …).