无法在Rails中显示CSS bg

时间:2014-07-06 18:08:42

标签: html css ruby-on-rails heroku

在我的应用程序的索引页面上工作,由于某种原因,我添加的bg-image没有渲染。但是我调用的所有其他图像文件都有(但是没有在CSS中调用,就像这样)

它在开发中表现得很完美,但在生产中却没有。

我的heroku日志中出现以下错误:

ActionController::RoutingError (No route matches [GET] "/assets/ctabackground.png"):

我的CSS:

#cta {
 text-align:center;
 height:600px;
 width:100%;
 background:url('ctabackground.png') no-repeat $light-green;
 h1, h2 {
 color:#fff;
}
 h2 {
  letter-spacing:2px;
  font-weight:300;
 }
}

该文件位于assets / images / as ctabackground.png

这里的问题是什么?

1 个答案:

答案 0 :(得分:0)

您需要使用rails asset_path来获取正确的网址。尝试:

background-image: url(<%= asset_path 'ctabackground.png' %>) no-repeat $light-green;

<强>更新

由于您使用的是sass,因此可以使用rails image-url helper

background-image: image-url('ctabackground.png') no-repeat $light-green;