如何在application.css中要求特定文件

如何在application.css中要求特定文件,css,ruby-on-rails,twitter-bootstrap,Css,Ruby On Rails,Twitter Bootstrap,我试图在我的Rails 4应用程序的application.css中要求“font awesome.scss”,如下所示: /* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. * * Any CSS and SCSS file within this directory, lib/assets/styl

我试图在我的Rails 4应用程序的application.css中要求“font awesome.scss”,如下所示:

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets,    vendor/assets/stylesheets,
 * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any styles
 * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
 * file per style scope.
 *
 *= require 'font-awesome.scss'
 *= require_tree .
 *= require_self
 */
“font awesome.scss”导入一组看起来像partials的文件,前面带有下划线。其中一个部分(_variables.scss)定义了一个变量,我需要在收到以下错误消息时定义该变量:

Sass::SyntaxError (Undefined variable: "$fa-css-prefix".
(in /Users/bla/rails_projects/Homepage/app/assets/stylesheets/_bordered-pulled.scss:4)):
app/assets/stylesheets/_bordered-pulled.scss:4
app/views/layouts/application.html.erb:35:in `_app_views_layouts_application_html_erb__3531690645719711557_70221015865520'
我做错了什么

只要这样做:

*= require font-awesome
不需要加引号或扩展名。
这里有更多关于这个主题的文档:

你可以在没有gem的情况下使用font-awesome,只需使用他们的cdn即可

这会出现在布局application.html.erb中

<head>
...
  <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
...
</head>  

...
...

此处的更多信息:

尝试检查您如何预编译资产。检查initializers/assets.rb(您也可以选择environments/production.rb)以确保以友好的方式预编译资产,如下所示:

config.assets.precompile += ["*.js", "*.scss", "*.jpg", "*.png"]
当它发生时,我也犯了同样的错误

config.assets.precompile += [/.*\.png/,/.*\.ico/,/.*\.jpg/,/.*\.js/,/.*\.scss/] 

谢谢你,尼克。但我已经试过了。Rails如何知道需要哪种字体?文件夹中有font-awesome.css。font-awesome.min.css和font-awesome.scss您是否使用font-awesome gem?如果是这样的话,这就应该奏效了。如果没有,请告诉我,我将删除此答案。您不能要求使用scss文件,您必须使用@importh。您是否尝试在tree和self之后要求使用字体。Bootstrap与基金会相似,我的基础文件在树和Soad之后总是需要适当地导入到资产管道中。另外,如果需要的话,您可能希望自己的CSS覆盖字体。