Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 5.1 : url helper for files in public folder

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?

like image 239
Nicolas Maloeuvre Avatar asked May 18 '17 07:05

Nicolas Maloeuvre


People also ask

How do you Precompile in rails?

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.

What is the use of public folder in Rails?

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.

What is Require_tree?

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.

What is Asset_path?

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 ...


1 Answers

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

like image 132
John Smith Avatar answered Sep 19 '22 07:09

John Smith