You can use erb in the sass file, but this is really a very bad idea, since your css will have to be parsed for each request (and the browser will not be able to cache it).
I would recommend just sticking to one css snippet directly on the watch page in a style tag. Therefore, it is rated on the page. It makes sense?
UPDATE (adding requested example)
Add this to your actual view (e.g. show.html.erb):
<style media="screen"> .image_div { background-image: url(<%= @object.image %>); } </style>
You can leave the background-position declaration in the css file as it is not dynamic. @object.image should return the actual path to the image, so if @object.image is a ruby ββobject, you need to access any property that @object.image.path path ( @object.image.path or @object.image.url or something that suits your codebase).
source share