How to get image url in css inside a public folder in Rails?
I have a css located inside the public/ folder in rails. I want to locate the images inside the app/assets/images/ folder for a background in the css. The code below doesn't seem to work:
This is normally used for css inside the app/assets/stylesheets/ folder. Can't make it work inside the public folder.
You have two alternatives. If you can rename the file and use the asset pipeline with SCSS, then rename the style to
.css.scss and replace
image-url SCSS helper.
It will automatically resolve the path.
Another solution is to rename the file to
.css.erb and you'll be able to use ERB code inside the file.
background-image: url(<%= asset_path 'bg-noise.png' %>)
The last solution is to hard-code the path.
I encourage you to use the first option.