Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 826
robertwbradford Avatar asked Jan 25 '12 17:01

robertwbradford


People also ask

How does Rails asset pipeline work?

The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB. Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets.

What does rails assets Precompile do?

The Rails asset pipeline provides an assets:precompile rake task to allow assets to be compiled and cached up front rather than compiled every time the app boots. There are two ways you can use the asset pipeline on Heroku. Compiling assets locally.

What is Require_tree?

The require_tree directive tells Sprockets to recursively include all JavaScript files in the specified directory into the output. These paths must be specified relative to the manifest file.

What is vendor folder in Rails?

Vendor is a directory to hold third party files, code, etc that you didn't write yourself.


1 Answers

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/. 
like image 68
Dylan Markow Avatar answered Sep 20 '22 21:09

Dylan Markow