I know this is probably an easy question but I am stumped here.
The application I am working on houses assets like so:
app
--assets
----fonts
----images
----javascripts
I like to organize assets efficiently to avoid a mess down the road so I am trying to break up images like so:
app
--assets
----fonts
----images
------icons
------views
--------home
--------admin
Ideally I would like to reference images like image.png
without having to add the folder path in front of the asset like views/home/image.png
which I believe has to be possible although not setup like that out of the box.
To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.
rails assets:precompile is the task that does the compilation (concatenation, minification, and preprocessing). When the task is run, Rails first looks at the files in the config.assets.precompile array. By default, this array includes application.js and application.css .
The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB. Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets.
It's possible if you manually add all paths underneath app/assets/images
to the Rails asset paths in your application.rb
:
Dir.glob("#{Rails.root}/app/assets/images/**/").each do |path|
config.assets.paths << path
end
In Rails 4+ any changes to asset paths should be made in:
config/initializers/assets.rb
To add all subdirectories in app/assets/images to the path, add the following:
Dir.glob("#{Rails.root}/app/assets/images/**/").each do |path|
Rails.application.config.assets.paths << path
end
Afterwards, you can verify the asset paths in the rails console with the following:
Rails.application.config.assets.paths.each do |p|
puts p
end
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