【问题标题】:css not loading image asset on rails 4css没有在rails 4上加载图像资产
【发布时间】:2015-08-09 07:46:14
【问题描述】:

我正在尝试从我的资产图像中显示一张简单的图像。我尝试以下方式:

#head {
background: #181015 url( ../images/header_bg.png) no-repeat;
background-size: cover;
min-height: 520px;
text-align: center;
padding-top: 240px;
color: white;
font-family: "Open sans", Helvetica, Arial;
font-weight: 300;
}

在我的assets/images 文件夹中,我还有其他图像。如果我设置其他图像,那么它工作正常。但是如果我尝试加载上面的图像,那么它就无法加载该图像。我在environments/development.rb中添加了以下内容

config.assets.debug = true
config.assets.compile = true
config.assets.precompile = ['*.js', '*.css', '*.css.erb']

我也运行了bundle exec rake assets:precompile,但它也无法加载该图像。该图像没有任何问题。因为我尝试使用具有相同 css 的简单 html 页面,它工作正常。我有什么遗漏吗。需要一些帮助。

【问题讨论】:

标签: html css ruby-on-rails image assets


【解决方案1】:

您是否尝试过使用 image-url 而不是 url。您可能需要将路径更改为“header_bg.png”(而不是包含图像目录)

我曾经做过的一个例子:

您是否也尝试过重新启动服务器以查看是否是这个原因?

Rails 有时处理资源的方式与将其与基本 CSS 链接时不同。您可能还想查看文档:

http://guides.rubyonrails.org/asset_pipeline.html

大约在第 2.3.2 节

【讨论】:

  • 谢谢你快速重播url( "header_bg.png") 为我工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-13
  • 2018-12-07
  • 1970-01-01
  • 2014-12-29
  • 2014-09-12
  • 1970-01-01
相关资源
最近更新 更多