Trying out Rails 8 for the first time. The Rails guide states:
The asset pipeline automatically evaluates ERB. This means if you add an
erb
extension to a CSS asset (for example,application.css.erb
), then helpers likeasset_path
are available in your CSS rules:.class { background-image: url(<%= asset_path 'image.png' %>) }
I need this to render fingerprinted assets.
But once I rename my application.css
to application.css.erb
, the stylesheet stops being served to my browser altogether.
As a workaround, I’ve tried keeping application.css
(no .erb
) and turning fingerprinting off per the guide, but that doesn’t work either: image paths are still fingerprinted.
What am I doing wrong?
As max pointed out, Propshaft handles asset paths automatically. There’s no need for css.erb
. From the docs:
Propshaft will automatically convert asset references in CSS to use the digested file names. So
background: url("/bg/pattern.svg")
is converted tobackground: url("/assets/bg/pattern-2169cbef.svg")
before the stylesheet is served.