Reputation: 1529
I need to install a series of libs in my application, keeping them in their respective folders inside /vendor/plugins/
Example, the ckeditor library:
/vendor/plugins/ckeditor/
/vendor/plugins/ckeditor/js/Chart.js
/vendor/plugins/ckeditor/css/chart.min.css
So that I can import into my application.scss like this:
*= require chart.min
And in my application.js like this:
//= require Chart.js
When I try to do this rails only accesses the folder /vendor/assets/plugins/
plugins, generating the error:
could not find file 'chart.min' with type 'text/css'
How do I get the project to scan all of the vendor's subfolders until find the file I'm importing?
Upvotes: 3
Views: 2932
Reputation: 102036
First add the /vendor/plugins
directory to the assets load path:
module MyApp
class Application < Rails::Application
config.assets.paths << Rails.root.join("vendor", "plugins")
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
end
end
However adding a directory to the assets load path does not mean that Sprockets will search all the subdirectories recursively. Nor is it a very good idea to configure it to do so.
You still need to provide a complete path from /vendor/plugins
.
app/assets/javascripts/application.js:
//= require ckeditor/js/Chart
app/assets/stylesheets/application.css:
*= require ckeditor/css/chart.min
Or you can just use the Rails integration gem and skip all the hassle.
Upvotes: 5