After this commit in Rails, it is suggested that 3rd party assets should either be put in the app/assets
folder or config.precompile
should list all such assets.
Quoting a use case on that thread
For example, if I need to vendor a jQuery plugin which also has CSS, a font face, and an image sprite, I'd add the .js and .css to vendor/assets/javascripts and vendor/assets/stylesheets. I would also vendor the sprites and fonts in vendor/assets/images and vendor/assets/fonts, respectively. Adding the entire vendor/assets path seems overkill, but manually specifying each asset individually seems tedious (though that might be by design).
Adding third party assets inside app/assets
will lead to a Rails 2 like problem of a global assets folder.
Am I missing something ? Whats the Rails 4 way of organizing third party assets.
Third parties should be included by hand explicitly. This is because these libraries have many optional parts such as source code, readme files etc. If you need other things such as images or fonts you can add this files in public folder or do this:
config/application.rb
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif,
"fontawesome-webfont.ttf",
"fontawesome-webfont.eot",
"fontawesome-webfont.svg",
"fontawesome-webfont.woff")
config.assets.precompile << Proc.new do |path|
if path =~ /\.(css|js)\z/
full_path = Rails.application.assets.resolve(path).to_path
app_assets_path = Rails.root.join('app', 'assets').to_path
if full_path.starts_with? app_assets_path
puts "including asset: " + full_path
true
else
puts "excluding asset: " + full_path
false
end
else
false
end
end
environment/production.rb
config.serve_static_assets = true
Then run bundle exec rake assets:precompile RAILS_ENV=production
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With