1

I am trying to create a rails 6 application. In rails 5 while sass was still applicable I would use image-url(xxx.png) to reference images within the asset pipeline. However, in rails 6 this is no longer applicable with web pack. I cannot seem to load up the image.

I have tried using different tags like asset-url, adjusting the url for a direct path but with no luck.

.banner { background-image: url(asset_path('home/head-banner.png')); ... }

.banner { background-image: image-url('home/head-banner.png'); ... }

The expected result is the fully hashed url for the image.

4

1 回答 1

4

A quick fix solution that should work:

  1. Rename the css file to use .scss (SASS extension)
  2. Then use image-url

This should work without fault and will allow you to use the rails helper functions.

于 2019-08-14T14:59:10.143 回答