How to load vendor asset folder in Rails 4?

Ruby on-RailsPluginsRuby on-Rails-Plugins

Ruby on-Rails Problem Overview


I have a plugin with many types of files, and its own tree structure (html, css, js, documentation, images, etc)

Rather than going through the plugin folder, and splitting all the css and js files into the vendor/assets/js/ vendor/assets/css/ folders, I want to just keep the entire plugin folder as is. For example,

vendor/assets/multipurpose_bookshelf_slider/

How do I make sure the paths load properly, and reference them in my manifest files?

Currently, I have some files place as follows (not exhaustive)

/my_app/vendor/assets/multipurpose_bookshelf_slider/css/skin01.css
/my_app/vendor/assets/multipurpose_bookshelf_slider/js/jquery.easing.1.3.js
/my_app/vendor/assets/multipurpose_bookshelf_slider/
/my_app/vendor/assets/multipurpose_bookshelf_slider/

I'm referencing them in

application.js

//= require multipurpose_bookshelf_slider/js/jquery.easing.1.3.js
//= require multipurpose_bookshelf_slider/js/jquery.bookshelfslider.min.js

application.css.scss

@import "css/bookshelf_slider";
@import "css/skin01";

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

Any folder created directly under assets will be added to the load paths. Files in that folder can be referenced as usual like so:

If you have

  • vendor/assets/custom/js/file.js

  • vendor/assets/custom/css/file.css

then vendor/assets/custom/ will be added to the load paths.

Include your files in the following files by doing the following:

application.js

//= require js/file

application.css.scss

@import "css/file";

Once that's done, make sure to restart your local server, since it is upon starting your server that the load paths get recognized.

Note: to see a list of load paths, type in your terminal rails c, then type Rails.application.config.assets.paths.

Solution 2 - Ruby on-Rails

If the application you're running has the assets-pipeline activated, it should find your assets after expanding the path in your application.rb

config.assets.paths << Rails.root.join("multipurpose_bookshelf_slider")

Solution 3 - Ruby on-Rails

I prefer D7na's answer but with a bit of improvement in my opinion.

As long as this is related to assets, I think it is better to be placed in the assets.rb file.

assets.rb:

Rails.application.config.assets.paths << Rails.root.join("multipurpose_bookshelf_slider")

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
QuestionahnbizcadView Question on Stackoverflow
Solution 1 - Ruby on-RailsahnbizcadView Answer on Stackoverflow
Solution 2 - Ruby on-RailsD7naView Answer on Stackoverflow
Solution 3 - Ruby on-RailsAyman SalahView Answer on Stackoverflow