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

时间:2015-04-08 18:11:00

标签: 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/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'

我做错了什么?

3 个答案:

答案 0 :(得分:1)

这样做:

*= require font-awesome

无需加上引号或扩展名。 有关此主题的更多文档:http://guides.rubyonrails.org/asset_pipeline.html

答案 1 :(得分:0)

你可以使用没有gem的字体真棒,只需使用他们的cdn。

这适用于您的布局,application.html.erb

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

此处有更多信息:http://fortawesome.github.io/Font-Awesome/get-started/

答案 2 :(得分:0)

尝试检查预编辑资产的方式。检查initializers / assets.rb(或者它可能是environment / production.rb),以确保以友好的方式预编译资产,如下所示:

config.assets.precompile += ["*.js", "*.scss", "*.jpg", "*.png"]

时我遇到同样的错误
config.assets.precompile += [/.*\.png/,/.*\.ico/,/.*\.jpg/,/.*\.js/,/.*\.scss/]