Rails 3.1 Asset Pipeline manifest file will not load javascripts

I have a whole MESS from javascripts to vendor / assets / javascripts. In my app / assets / javascripts / application.js file, I have a directive:

//= require_tree . 

Does this only mean the current directory app / assets / javascripts, not lib / assets or vendor / assets?

If I explicitly enable javascripts, it works. I just do not want to do this if I do not need it.

Is there something I'm missing that will allow the asset pipeline to automatically serve assets from outside the application directory (lib and vendor)?

+4
source share
3 answers

require_tree only retrieves the assets found in the application.js file.

lib/assets and vendor/assets already included in the search paths for the pipeline ( see this code ).

You can include these files using the second manifest.

Go to vendor/assets/javascripts and create a file called misc_vendor.js

Inside the append, add the require_tree directive.

Then refer to this file from the application.js manifest:

 require misc_vendor 

If you are having problems with the download order, you can manually request the provider files in the order you need, instead of using require_tree.

As part of the conversion to the pipeline, this may be a good chance to clean things up !:-)

+5
source

Alternatively, you can do this without a second manifest like this:

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

The path must refer to the manifest file app / assets / javascripts / application.js.

+1
source

You need to expand the path in the application.rb file as follows.

 config.assets.paths << "#{Rails.root}/vendor/assets/some file name" 

See this guide for more details.

0
source

Source: https://habr.com/ru/post/1390338/


All Articles