加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – 如何在Rails 4.0中引用生产中的CSS背景图像

发布时间:2020-12-16 21:57:46 所属栏目:百科 来源:网络整理
导读:我将应用从3.2.12切换到4.0.0.rc1.当我以后在生产中看过它,背景图像就消失了.我的图像资源的其余部分没有问题. 在我的日志中,我看到所有成功渲染的图像都有一个摘要贴在他们的最后,像这样: 2013-05-12T19:57:05.856277+00:00 heroku[router]: at=info metho
我将应用从3.2.12切换到4.0.0.rc1.当我以后在生产中看过它,背景图像就消失了.我的图像资源的其余部分没有问题.

在我的日志中,我看到所有成功渲染的图像都有一个摘要贴在他们的最后,像这样:

2013-05-12T19:57:05.856277+00:00 heroku[router]: at=info method=GET path=/asset/explore-9ec2a1cfd4784133755637f6ef6d5673.png host=xxx.herokuapp.com fwd="69.140.148.75" dyno=web.1 connect=3ms service=5ms status=200 bytes=4064

而我的不成功的背景图片没有摘要,加上一个404回复代码:

2013-05-12T19:57:05.736354+00:00 heroku[router]: at=info method=GET path=/assets/background.png host=xxxx.herokuapp.com fwd="69.140.148.75" dyno=web.1 connect=2ms service=7ms status=404 bytes=728

在production.rb文件中,有一个配置行,用于缓存:

# Generate digests for assets URLs
config.assets.digest = true

这是背景的CSS:

body {
  background-image: url('background.png');
  background-attachment: fixed;
  background-position: 100% 100%;
  background-repeat: no-repeat;
}

我得出结论,我的CSS文件试图获取一个不存在的图像url,因为它引用了没有最后的哈希的普通资源(“background.png”).这只是CSS中图像的问题;我的.erb文件中引用的所有图像都很好.那么如何在我的CSS中引用这个资源呢?是否有任何解决方法?

谢谢阅读.

解决方法

使用asset-url. Rails将对此进行预处理,并扩展正确的URL.
body {
  background-image: asset-url('background.png');
  background-attachment: fixed;
  background-position: 100% 100%;
  background-repeat: no-repeat;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读