Rails asset pipeline: Standard way for including all /vendor/assets/javascripts/?

Ruby on-Rails-3.1Asset PipelineSprockets

Ruby on-Rails-3.1 Problem Overview


I've been transitioning an app to Rails 3.1 (and now on to 3.2) and watched the Railscast on the asset pipeline. I moved all of my third-party jquery plugin files to the /vendor/assets/javascripts/ directory. In my /app/assets/javascripts/application.js I have the following:

//= require jquery
//= require jquery_ujs
//= require_tree .
//= require_self

I realized the require_tree . call only loads the tree for the /app/assets/javascripts/ directory. (Is that correct?) What's the best way to include all the "vendor" javascripts? (I'm not worried about ordering at this point.) Of course I could require them line by line in /app/assets/javascripts/application.js. My other thought was to create /vendor/assets/javascripts/vendor_javascripts.js with the following:

//= require_tree .

And then in /app/assets/javascripts/application.js add the following:

//= require vendor_javascripts

This seems a little clunky though. Is there a better way to automatically include all the "vendor" (and/or "lib") javascripts?

PS. I saw this about index.js files, but I would potentially end up with multiple files named index.js, right? Oh, and I tried restarting my server throughout.

Ruby on-Rails-3.1 Solutions


Solution 1 - Ruby on-Rails-3.1

You can add something like this in your app/assets/javascripts/application.js file to include all the vendor javascripts:

//= require_tree ../../../vendor/assets/javascripts/.

Solution 2 - Ruby on-Rails-3.1

I know it's an old question, but you can create a manifest file on the vender/assets/javascript folder:

 #vendor/assets/javascripts/my_jquery_plugins/manifest.js
 # require_tree .

And in you application.js:

 //= require my_jquery_plugins/manifest.js

If you're using Rails 4, name the manifest.js as index.js and in your application.js:

//= require my_jquery_plugins

It's less hacky than relative path described.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrobertwbradfordView Question on Stackoverflow
Solution 1 - Ruby on-Rails-3.1Dylan MarkowView Answer on Stackoverflow
Solution 2 - Ruby on-Rails-3.1lcguidaView Answer on Stackoverflow