通过.erb预处理程序未运行资产 [英] Assets not being run though the .erb preprocessor

查看:65
本文介绍了通过.erb预处理程序未运行资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试在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:

  1. 我决定通过将样式表扩展名从 css 更改为 scss 来做到这一点.
  2. 我的代码中的图片引用已从
  1. I decided to do this the SASS-way by changing my stylesheet extensions from css to scss.
  2. 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会使我
<link href="/assets/print-e47f5a48af04ce6854c840d74cd28fba.css?body=1"
<link href="/assets/favicon-15fb5e00d868940bc32db7996e10f594.png" ...

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆