Rs Graphics
Rs Graphics

Reputation: 193

Ruby on Rails 6 how to reference images from asset pipeline for css

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.

Upvotes: 2

Views: 4010

Answers (1)

Rishi
Rishi

Reputation: 351

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.

Upvotes: 5

Related Questions