Reputation: 111
I am completely new to Ruby on Rails and I'm trying to serve an application in which an html file calls javascript that is located in a separate file. I placed the javascript file in the javascripts fold of my rails application. My html displays fine but when I press a button that is intended to call a javascript function I receive an error.
Uncaught TypeError: Cannot call method 'myMethod' of undefined
I can see that the file is present by looking in the resources tab of google chromes developer tools. It also looks like rails is correctly including the javascript file in the html file.
<script data-turbolinks-track="true" src="/assets/myScript.js?body=1"></script>
I'm not sure what I'm doing wrong. Any help would be greatly appreciated.
Upvotes: 0
Views: 69
Reputation: 76774
You should really use the javascript_include_tag helper to keep the app to convention:
<%= javascript_include_tag "myScript" %>
The error is to do with your Javascript's call to myMethod
. The error will be caused by referencing myMethod
on an object / var which doesn't exist
Upvotes: 1