将图像资源引用为内联 CSS

Referencing image asset as in-line CSS

根据通过资产管道存储的图像,动态调用图像作为 div 的背景。使用载波,呼叫将是

  <div class="row imaged-background" style="background:<%= image-url(@staticpage.image_url.to_s) %>"> 

但是,这会导致:

undefined local variable or method `image

去掉<%=只会得到background: image-url(@staticpage.image_url.to_s)

如果这有用,这个有效:

background-image: url(<%= @staticpage.image_url.to_s %>)

carrierwave 似乎在使用 rails 助手。