Here's what works:
It's great to add .erb files to .css and use the ruby ββ/ rails code. So the snippet in my question above is good.
You should add a line like this to /config/environments/production.rb
config.assets.precompile = ['*.css.erb']
Then, when you run RAILS_ENV=production bundle exec rake assets:precompile , a fingerprint file will be created and the image path will be inserted correctly.
So that solved my problem.
For me .js files are automatically compiled without adding any configuration parameters. But css or css.erb files did not work. So this is what I actually use:
config.assets.precompile = ['*.js', '*.css', '*.css.erb']
source share