I have created a new Rails 4 project and I am trying to load an external JavaScript file in my HTML file. I have placed the JavaScript file in the /assets/javascripts
directory and included the file in my HTML file.
My HTML file:
<html> <body> <script src="/assets/hello.js"></script> </body> </html>
My JavaScript file:
document.write("test");
I do not see any errors in my web browser console when loading the website. I am pretty sure I put the JavaScript file in to correct directory but the file will not run. Does Rails require something for external JavaScript files to work properly?
I have also tried defining a method in the JavaScript file and calling it within a <script>
tag but I get a "Uncaught ReferenceError: methodname is not defined".