1

我想在 Rails 3.1 中使用清单方法

 /*
  *= require_self
  *= require_tree .
  */

但是,我还需要指定一个编码指令

 @charset "UTF-8";

这两个似乎都需要在第一行进行解释,但只有一个可以。所以要么我得到我的 charset 指令,要么得到 Sprockets 清单。

我怎样才能得到两者?

4

3 回答 3

1

只需放置@charset "UTF-8";在任何不使用 Sprockets要求指令的所需 css/sass 文件中,它就会被正确编译到 application.css 的顶部(请参阅处理 @charset in CSS concatenations

UPD:另一种方法是@charset "UTF-8";在 Sprockets 注释之后添加。无论如何,Sprockets 会将其剪切并插入页面顶部。

于 2011-06-28T15:13:12.503 回答
0

UPD:另一种方法是添加@charset "UTF-8";在 Sprockets 评论之后。无论如何,Sprockets 会将其剪切并插入页面顶部。

这对我很有用,只需要确保你也包含 require_self ——在我开始之前,我的 application.css 没有包含这个,所以它没有选择我的 @charset = "UTF8";

最终结果最终看起来像这样——以防万一其他人为此撞墙:

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
 * the top of the compiled file, but it's generally better to create a new file per style scope.
 *= require_self
 *= require <your other requires go here>
*/
@charset "utf-8";
于 2011-09-05T16:59:45.457 回答
0

纳什的回答可能在某一时刻有效,但对我没有用。我不得不通过在评论中添加一个 utf-8 字符来欺骗 Sprockets 将 charset 设置为 utf-8:

// é

来源: https ://github.com/sstephenson/sprockets/issues/220

于 2013-04-10T22:54:27.340 回答