Rails pipeline: standard way to include all / vendor / assets / javascripts /?

I translated the application into Rails 3.1 (and now at 3.2) and looked at Railscast in the asset pipeline . I moved all the files of third-party jquery plugins 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 that calling require_tree . only loads the tree for the / app / assets / javascripts / directory. (Is this right?) What is the best way to include all the "vendor" javascripts? (I'm not worried about ordering at the moment.) Of course, I could request them one by one 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 

It seems a little awkward. Is there a better way to automatically include all "vendor" (and / or "lib") javascripts?

PS. I saw about index.js files , but I could end up creating several files called index.js, right? Oh, and I tried restarting my server.

+53
asset-pipeline sprockets
Jan 25 '12 at 17:05
source share
2 answers

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

 //= require_tree ../../../vendor/assets/javascripts/. 
+72
Jan 25 '12 at 17:12
source share

I know this is an old question, but you can create a manifest file in the vender / assets / javascript folder:

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

And you have application.js:

  //= require my_jquery_plugins/manifest.js 

If you are using Rails 4, name manifest.js as index.js and in application.js :

 //= require my_jquery_plugins 

This is less hacky than the relative path described.

+21
Sep 26 '14 at 1:45
source share



All Articles