我在Rails(3.2.7)中遇到了关于资源预编译的问题。
我像这样包含一个favicon:
<link rel="icon" type="image/png" href="<%= image_path("favicon.png") %>" />
在开发模式下,我设置了
config.assets.compile = true
。一切都运行良好,渲染的HTML如下:<link rel="icon" type="image/png" href="/assets/favicon.png" />
但是在生产环境中,当我设置config.assets.compile = false
时,就会出现错误。
Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Home#index
...
favicon.png isn't precompiled
我已经运行了
rake assets:precompile
,我可以清楚地看到,该资源可在public/assets/favicon.png
下使用。我知道,在生产环境中我可以设置
config.assets.compile = true
,但我不想这样做(因为性能原因)。有人知道为什么我的Rails应用程序无法在生产环境中解析正确的资源路径吗?谢谢!
更新: 也许还有用的是:它不仅发生在图像上,也发生在其他资源上。
例如,
<%= stylesheet_link_tag "screen", :media => "all" %>
也会在将config.assets.compile
设置为false时产生错误screen.css isn't precompiled
。