In Rails 5.1, there is a deprecation warning if we use asset_path for files in public folder.
DEPRECATION WARNING: The asset "favicon.ico" is not present in the asset pipeline.Falling back to an asset that may be in the public folder.
This behavior is deprecated and will be removed.
So I tried public_asset_path
, but it is not working, is there a helper?
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.
public. The public directory contains some of the common files for web applications. By default, HTML templates for HTTP errors, such as 404, 422 and 500, are generated along with a favicon and a robots. txt file.
The require_tree directive tells Sprockets to recursively include all JavaScript files in the specified directory into the output. These paths must be specified relative to the manifest file.
asset_path(source, options = {}) public. This is the entry point for all assets. When using the asset pipeline (i.e. sprockets and sprockets-rails), the behavior is “enhanced”. You can bypass the asset pipeline by passing in skip_pipeline: true to the options. All other asset *_path helpers delegate through this method ...
If want to use helper method without asset pipeline, need to specify the skip_pipeline
option.
Like this.
image_path("user/favicon.png", skip_pipeline: true)
Or if want to enable asset fallback for the entire application,
config.assets.unknown_asset_fallback
can be set to true.
See: http://guides.rubyonrails.org/asset_pipeline.html#raise-an-error-when-an-asset-is-not-found
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