Rails 3.1 不会预编译 CSS 未引用的图像?
我收到以下错误:
Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Photos#edit
Showing .../app/views/photos/_form.html.haml where line #49 raised:
taxonomy/focus-building.jpg isn't precompiled
Extracted source (around line #49):
46: = focus.code
47: .tooltip
48: %span.name= focus.name
49: = image_tag("taxonomy/focus-#{focus.code.downcase.dehumanize}.jpg")
50: / Help Overlay
51: .help
52: %a.overlay{:href=>"#", :rel=>'#help-focus'} Learn more about focus
此图像文件位于 app/assets/images/taxonomy/focus-building.jpg
。我已经运行了rake assets:precompile RAILS_ENV=product
,但据我所知,图像没有被复制到public/assets
目录中。
奇怪的是,SCSS 中使用 image-url() 引用的所有资源都工作正常。为什么使用 image_tag
引用此图像时报告未进行预编译?
I am getting the following error:
Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Photos#edit
Showing .../app/views/photos/_form.html.haml where line #49 raised:
taxonomy/focus-building.jpg isn't precompiled
Extracted source (around line #49):
46: = focus.code
47: .tooltip
48: %span.name= focus.name
49: = image_tag("taxonomy/focus-#{focus.code.downcase.dehumanize}.jpg")
50: / Help Overlay
51: .help
52: %a.overlay{:href=>"#", :rel=>'#help-focus'} Learn more about focus
This image file is located in app/assets/images/taxonomy/focus-building.jpg
. I have run rake assets:precompile RAILS_ENV=production
, but as far as I can tell the images are not being copied to the public/assets
directory.
Strangely, all assets that are referred to in SCSS using image-url()
work fine. Why does this image report not being precompiled when referred to with image_tag
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果启用了 assets.digest 选项,这将在名称末尾添加一个哈希,因此对该文件的静态引用将不再起作用,请更改任何静态引用的资产,以便它们使用辅助方法。
If you have the assets.digest option enabled this will add a hash at the end of the name and so a static reference to that file will no longer work, change any statically-referenced assets so that they use the helper methods.
我对 image_tag 也有同样的问题。我通过使用实时编译解决了这个问题。
在 Production.rb 中
I had the same problem with image_tag. I got the problem solved by using live compilation.
In production.rb