资产未通过 .erb 预处理器运行 [英] Assets not being run though the .erb preprocessor
问题描述
我在我的 rails 3.1 应用程序中尝试 rake assets:precompile
时遇到问题.我不断收到以下错误:
I am having trouble trying to rake assets:precompile
in my rails 3.1 app. I keep getting the following error:
rake aborted!
Invalid CSS after "...und-image: url(": expected ")", was "<%= asset_path(..."
似乎erb 预处理器没有被调用,但我的文件名为style.css.scss.erb
.有什么建议吗?
It seems that the erb preprocessor is not being invokeb but my file is called style.css.scss.erb
. Any suggestions?
推荐答案
Ruby 文档在一些事情上似乎有点不清楚,例如 asset_path
和样式表中的其他此类帮助程序的使用.无论如何,这就是我为解决完全相同的问题所做的工作:
Ruby documentation seems a bit unclear on a few things such as the usage of the asset_path
and other such helper in stylesheets. Anyways this is what I did to get around the exact same problem:
- 我决定通过将我的样式表扩展从 css 更改为 scss 来采用 SASS 方式.
- 我的代码中的图像引用从
- I decided to do this the SASS-way by changing my stylesheet extensions from css to scss.
- The image references in my code were changed from
background-image: url(<%= asset_path 'blah.png' %>);
到
background-image: image-url("blah.png");
我在 RailsGuides
<小时>
我还在我的 config/appliction.rb
文件中添加了 config.assets.digest = true
行,因为这似乎让我的输出 HTML 引用散列的文件名.如果没有将 digest
标志设置为 true,我的所有链接标签都以 <link href="/assets/print.css?body=1" ...
或 <href="/assets/favicon.png"...
这几乎违背了使用资产管道的目的.尤其是 favicon 文件仍然会被服务器和 CDN 缓存.
I've also added the config.assets.digest = true
line to my config/appliction.rb
file because that seemed to get my output HTML to refer to the hashed filenames. Without the digest
flag set to true I get all of my link tags starting off with <link href="/assets/print.css?body=1" ...
or <href="/assets/favicon.png"...
which pretty much defies the purpose of using the assets pipeline. Especially the favicon file will still be cached by the servers and CDN's along the way.
明确地将摘要标志设置为 true 让我<linkhref="/assets/print-e47f5a48af04ce6854c840d74cd28fba.css?body=1"
和 <link href="/assets/favicon-15fb5e00d868940bc32db7996e10f>code ...
Explicitely setting the digest flag to true gets me <link href="/assets/print-e47f5a48af04ce6854c840d74cd28fba.css?body=1"
and <link href="/assets/favicon-15fb5e00d868940bc32db7996e10f594.png" ...
这篇关于资产未通过 .erb 预处理器运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!