Firstly, enter the following line in the view that needs JavaScript code:
<%= javascript_include_tag "my_js_file" %>
This line ensures that my_js_file.js is included in the current view (note that in the "include tag" the ".js" is omitted).
Secondly, simply code/add your JavaScript file to /app/assets/javascripts/. It will now be available in your view!
I am somewhat conflicted as to how valuable this modus operandi is (there are a few good articles arguing about the benefits of using CoffeeScript); however, at the current moment it is the best solution I have found. If you know any tips about linking CoffeeScript to Rails, please comment below!
No comments:
Post a Comment