【问题标题】:Background image not showing up in heroku背景图片没有出现在heroku中
【发布时间】:2014-03-25 07:32:57
【问题描述】:

我的 heroku 网站的背景图片有问题,在本地使用

background-image: url('background_stripe.png');

有效,但部署时文件损坏

我试过了

background-image: image-url('background_stripe.png');
background-image: url(image-url('background_stripe.png'));
background-image: url(image_url('background_stripe.png'));

在本地或heroku上都没有。

使用 bash 我发现 heroku 已将图像文件命名为 background_stripe.png 但它没有散列并且图像损坏

【问题讨论】:

  • background_stript.png 图像是否与 HTML & CSS 页面位于同一文件夹中? background-image: url('background_stripe.png'); 是定义它的正确方式 - 可以找到示例 here
  • 那张图片的绝对路径是什么?
  • 是的,它被定义为 background-image: url('img');已经,但它不起作用,@Paritosh Piplewar app/assets/images/background_stripe.png
  • iamge-url 是您的代码中的错字还是您的问题?还有,编译后的 CSS 是什么样子的?
  • @cimmanon 很好,只是问题中的一个错字:P

标签: css ruby-on-rails image heroku sass


【解决方案1】:

当您的资产被编译用于生产时,它们会在它们的末尾添加一个“摘要”以用于版本控制。如果您在视图中定义类,则应使用 asset_path('background_stripe.png');如果您在 SCSS 文件中定义它们,请使用 the docs 中引用的 image-url('background_stripe.png')

【讨论】:

  • 是的,我也使用了 image-url,因为它在 app/assets/images 中,但它似乎不起作用
  • 使用 image_url 为我工作,用下划线代替破折号。
【解决方案2】:

在您的 production.rb 中添加以下行

config.serve_static_assets = true
config.assets.compile = true

或者您可以尝试使用在本地预编译资产

RAILS_ENV=production rake assets:precompile

【讨论】:

  • 这工作谢谢!专门将值更改为 true。
  • 更改 production.rb 有效。谢谢,@deep。看起来config.serve_static_assets 将被弃用。 config.serve_static_files 应该在它的位置使用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-12
  • 1970-01-01
  • 2021-06-06
  • 1970-01-01
  • 1970-01-01
  • 2022-07-21
  • 1970-01-01
相关资源
最近更新 更多