将 rails 路由调用到 CSS(在 haml 中)

Call a rails route into CSS (in haml)

= @photo.image.url(在 haml 中)将根据视图

编译图像的 url

我想使用下面 CSS 中的标签生成的图像 link,但这行不通。

#BG {
  background: url( HERE!!! ) no-repeat center center fixed;
  -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    height: 400px;
}

我已经尝试 javascript 直接在页面上用新图像替换固定图像以进行测试...但是没有用。我玩过下面的代码并尝试了很多不同的版本。

:javascript
  document.getElementById('BG').style.background = "url('newimg.jpg') no-repeat center center fixed"

这是将使用它的 Haml 代码:

 #BG
  This div should have the image as a background
  %p= @photo.title
.container
  .jumbotron

我需要一个解决方案来让图像 url 进入背景 url

插入值@photo.image.url并将其添加到字符串

呈现标签时在 HAML 中

#BG{style: "background: url(#{@photo.image.url}) no-repeat"}

CSS

#BG {background: url("#{@photo.image.url}")}