Rails 4.1图像url仍在调用未编译的资产 [英] Rails 4.1 image url's still calling uncompiled assets
问题描述
所以我有大量的生产轨道网站,但我意识到我失踪了一些图像。我看着我的预编译css文件,图像url直接调用图像直接像 url(/assets/gototop.png)
它不会找到,因为我的图像现在例如 gototop-6c119f88349ddd550e3efcf5bbefe1ad.png
。
So I have got my rails site up on production for the most part but I realized I was missing a few images. I looked at my precompiled css file and the image url's are calling the images directly like url(/assets/gototop.png)
which it won't find since my image is now something like gototop-6c119f88349ddd550e3efcf5bbefe1ad.png
.
如何让我的css指向预编译的图片文件?
How do I get my css to point to the precompiled image file?
更新:链接文件我意识到我可以使用asset_path方法,但不幸的是,我使用scss,我不能只是添加.erb到文件的末尾...似乎rails不喜欢使用多个编译器。 (我试过)
Update: also as stated in the linked file I realize I could use the asset_path method but unfortunately I am using scss and I can't just add .erb to the end of the file...seems rails doesnt like to work with multiple compilers. (I tried)
推荐答案
这是由资产指纹(不仅仅是Rails 4.1问题)
This is a common problem caused by asset fingerprinting (not just a Rails 4.1 issue)
修复它的方法是在CSS中使用预编译器(Rails自带 SASS )。预编译器基本上意味着你可以处理CSS文件,如 erb
- 使用某些助手&变量:
The way to fix it is to use a precompiler in your CSS (Rails comes with SASS). A precompiler basically means you can treat CSS files like erb
-- use certain helpers & variables:
#app/assets/stylesheets/application.css.sass
body
background: asset_url("/layout/gototop.png")
asset_url
(似乎现在称为 asset-url
)基本上允许您通过指纹名称调用资产
asset_url
(seems it's now called asset-url
) basically allows you to call assets by their fingerprinted name
我们的讨论,你还需要用 rake assets:precompile RAILS_ENV = production
来做到这一点。在控制台中触发此命令后,它按预期工作
As per our discussion, you also need to do this with rake assets:precompile RAILS_ENV=production
. After firing this command in the console, it worked as expected
这篇关于Rails 4.1图像url仍在调用未编译的资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!