Search code examples
ruby-on-railsasset-pipeline

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

  • 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