【发布时间】:2013-10-14 17:24:00
【问题描述】:
我正在尝试使用background-image 显示图像,但我尝试过的任何方法都不起作用。但是,视图中的image_tag()s 工作得很好。
我试过了:
background-image: url("images/icons/heart.png")
background-image: url("icons/heart.png")
background-image: image-url("images/icons/heart.png")
background-image: image-url("icons/heart.png")
background-image: asset-url("images/icons/heart.png")
background-image: asset-url("/icons/heart.png")
background-image: asset-data-url("images/icons/heart.png")
background-image: url(image-path("icons/user_comment.png"))
每次重新运行rake assets:precompile
只有asset-data-url 有效,但是因为它将图像的数据存储到CSS 中,这是多余的。无论出于何种原因,我都无法让它在生产中呈现正确的 CSS。它总是出现在background-image: url("/images/icons/heart.png") 或类似的地方,但最后没有应用哈希。
其中大部分都在开发中。
为什么image_tag 会生成正确的 url,而这些不会?
【问题讨论】:
-
你是如何在生产环境中生成 css 的?你用对了吗
RAILS_ENV? -
您使用的是哪些生产映像?如果您使用asset_sync gem,它会弄乱图像(我们正在修复)。您的图片在 CSS 与服务器上的引用情况如何?
-
@phoet
RAILS_ENV正在生产中。 CSS 文件只是存储在 app/assets/stylesheets 中。 @rich-peck 我没有特别使用任何 gem 来引用 CSS。在本地,CSS 显示background-image: url("assets/icons/heart.png")。 -
@h7u9i 看起来资产是用开发环境编译的。
-
@phoet 知道如何改变它吗?我在启动 Apache 时肯定会指定
production。
标签: css ruby-on-rails ruby-on-rails-4