Rails 3.1 不会预编译 CSS 未引用的图像?

发布于 2024-12-08 16:18:31 字数 947 浏览 0 评论 0原文

我收到以下错误:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苄①跕圉湢 2024-12-15 16:18:31

如果启用了 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.

云巢 2024-12-15 16:18:31

我对 image_tag 也有同样的问题。我通过使用实时编译解决了这个问题。

在 Production.rb 中

  • config.assets.compile = true

I had the same problem with image_tag. I got the problem solved by using live compilation.

In production.rb

  • config.assets.compile = true
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文