Rails4:image_url不在scss中生成摘要 [英] Rails4: image_url not generating digest in scss
问题描述
我不明白为什么我的css文件没有使用辅助方法image_url
I can't understand why my css file is not appending digests to my assets with the helper method image_url
我的资产已正确预编译,并且文件中确实包含摘要.我也可以手动访问它们(使用摘要的URL).最奇怪的是,在一开始它就起作用了.
My assets are correctly precomiled, and files do contain the digest. I also can access them (with the digested url) manually. And most strange thing is that in the beginning it was working.
这是我的配置:
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'
config.serve_static_assets = false #also tried true
这是我的application.css: * = require_tree.
here's my application.css: *= require_tree .
这是common.scss文件,用于包含图像:
here's the common.scss file, used for including an image:
body{
background: image_url('bg.jpg');
font-family: 'Lato', sans-serif;
overflow-x: hidden;
}
图像以及样式表位于资产/图像和资产/样式表内的子文件夹中.
The images, as well as the stylesheets are in a subfolder inside assets/images and assets/stylesheets.
这是我的宝石:
gem 'rails', '4.0.0'
gem 'sass-rails', '~> 4.0.0'
我正在使用capistrano进行部署,但是我不认为这是与capistrano相关的问题,资产编制得很好.
I'm deploying with capistrano, but I don't think this is a capistrano related problem, assets are well compiled.
编辑 直到现在,我一直尝试过的(未成功):
EDIT What i've (unsuccessfully) tried until now:
image-url('image.jpg'); -> http://www.mydomain.it/images/image.jpg
image_url('image.jpg'); -> same as above
url(image-path('header.jpg')); -> http://www.mydomain.it/images/image.jpg
asset-url('image.jpg', image); -> http://www.mydomain.it/image.jpg
问题仍然存在:资产已编译但没有摘要即可被请求.
problem still remains: assets are compiled but requested without digest.
编辑
Following this question Rails 4 image-path, image-url and asset-url no longer work in SCSS files I moved around my assets and using the combination of asset-url and putting my assets in /public folder, background images are working, even though the problem still remains as the application is not using the timestamped version of the images. So only a (not that good, nor that bad) workaround.
推荐答案
应使用asset_path
.另外,由于SCSS不会编译asset_path,因此它需要在ERB标签下运行.将common.scss
重命名为common.scss.erb
Should use asset_path
. Also, it needs to run under ERB tag, as SCSS does not compile asset_path. Rename common.scss
to common.scss.erb
.body { background-image: url(<%= asset_path 'bg.jpg' %>) }
在此处了解更多信息.
这篇关于Rails4:image_url不在scss中生成摘要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!