Everything seems to work fine apart from the $.getScript("/comments.js part. I have tried to fix it but with no luck.
I have my application.js file which has:
$(function() {
setTimeout(test, 1000);
});
function test () {
$.getScript("/comments.js")
setTimeout(test, 1000);
}
$.getScript("/comments.js", function(){
updateComments();
});
and my index.js.erb in the views/comments
function updateComments(){
alert("testing");
}
my comments controller
def index
# ...
end
layouts/application.html.erb
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
I am just trying to see if I can get it to work but it just does nothing.
If you are trying to use any method from the script which you are loading using
getScriptthen wait untill the script is loaded. Use its callback method which will be called once the script is loaded on the page. Try this.Also make sure the path of the js file is correct.