【发布时间】:2014-10-12 06:11:08
【问题描述】:
当我使用 git push heroku master 将我的网站投入生产时,我的 CSS 中的 url 没有引用正确的图像 url。
这是我在开发环境中的情况:
- app/assets/images/logo.png 存在
- app/views/layouts/application.html.erb:
<%= stylesheet_link_tag "style" %> - app/assets/stylesheets/style.css:
background: asset-url("logo.png");
这是我在生产中的情况(当我“查看页面源代码”时):
- 不知道怎么找到logo.png?
- 链接到我的 CSS:
<link href="/assets/style-75a5c3912777c4b39ba92d1893ac7815.css" media="screen" rel="stylesheet" /> - 在我的(压缩的)CSS 中,我可以找到:
background:asset-url("logo.png");
对于直接从 app/views/* 调用的其他图像,没关系 (<%= link_to image_tag("xxx.png") %>)
在 config/environments/production.rb 我有:
config.assets.precompile += ['style.css']
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
config.assets.digest = true
config.assets.compile = true
config.serve_static_assets = true
我正在关注this great tutorial。
【问题讨论】:
-
那么它在生产中指的是什么 URL?因为如果你编译的 CSS 仍然显示
asset-url('logo.png'),那么你做错了什么。 -
CSS 仍然显示asset-url('logo.png') .... :/
-
@ZazOufUmI 你是如何为你的图片制作网址的?你确定 logo.png 存在于 app/assets/images 而不是 app/assets/images/some_folder 因为。如果它在 images 文件夹中,那么 assets-url 或 image-url 将为您创建正确的路径
-
你是从 sass/scss 编译 CSS 文件吗?他们为您提供了
asset-url辅助方法。 -
我更新了我的请求。是的@sevenseacat 我曾经使用过这些命令来帮助我解决另一个问题:stackoverflow.com/questions/19695809/…
标签: css ruby-on-rails image asset-pipeline production