'How to correctly add javascript libraries to my rails app
I want to include waypoints.js and counterup.js in my rails app, but I can't seem to figure out where to put them and how to require them. At the moment I have both .js files in vendor/assets/javascripts.
I then try to require them from my application.js but I get a sprockets::filenotfound error.
Application.js :
//= require jquery3
//= require jquery.turbolinks
//= require counterup
//= require waypoints
//= require popper
//= require bootstrap-sprockets
//= require jquery_ujs
//= require_tree .
//= require turbolinks
Am I correctly placing them in vendor/assets?
How do I correctly 'require' them?
Thanks
Solution 1:[1]
First of all check whether any kind of gems already exists for such library. If it's not I usually finish with placing it into app/assets/javascripts and including it in application.js as an average script.
Maybe it would be slightly better to create a special folder like app/assets/javascripts/src or something like this to keep all third-party libraries
Solution 2:[2]
Third party libraries should be added to vendor/javascript and not to app/assets/javascripts
Then in app/javascript/application.js you add the line
//= require FILENAME
Real example of getting howler.js. Get the howler.js file and put it in vendor/javascript
Then add the line //= require howler to app/javascript/application.js
Here is a video explaining this video explanation adding third party js libraries
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | AntonTkachov |
| Solution 2 | pcatre |


