@import'font-awesome'在Rails中不起作用

时间:2016-08-06 19:14:01

标签: css ruby-on-rails import sass font-awesome

我正在努力:

@import "font-awesome-sprockets";
@import "font-awesome";

在我的application.css.scss文件的末尾。

首先使用fontawesome网站提供的说明,然后与this stackoverflow topic

一样

然后如此github topic

这些解决方案都不适合我。

我的宝石文件:

source 'https://rubygems.org'
gem 'rails'
gem 'sqlite3'
gem 'sass-rails', '~> 5.0.4'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'font-awesome-sass', '~> 4.4.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
group :development, :test do
  gem 'byebug'
end
group :development do
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

我的application.html.erb主管部分:

<head>
  <title>Grzegorz Milanowski - Personal Website</title>
    <link href='https://fonts.googleapis.com/css?family=Raleway:400,700,800' rel='stylesheet' type='text/css'>
          <!--<link rel="stylesheet" href="font-awesome-4.6.3/css/font-awesome.min.css">-->
    <link rel="stylesheet" href="css/application.css">
    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
    <%= csrf_meta_tags %>
</head>

错误:

Sass::SyntaxError in Welcome#index
Showing /home/ubuntu/workspace/app/views/layouts/application.html.erb where line #8 raised:

File to import not found or unreadable: font-awesome-sprockets.
Load paths:
  /home/ubuntu/workspace/app/assets/images
  /home/ubuntu/workspace/app/assets/javascripts
  /home/ubuntu/workspace/app/assets/stylesheets
  /home/ubuntu/workspace/vendor/assets/javascripts
  /home/ubuntu/workspace/vendor/assets/stylesheets
  /usr/local/rvm/gems/ruby-2.3.0/gems/jquery-rails-4.1.1/vendor/assets/javascripts
  /usr/local/rvm/gems/ruby-2.3.0/gems/coffee-rails-4.1.1/lib/assets/javascripts
  /usr/local/rvm/gems/ruby-2.3.0/gems/turbolinks-source-5.0.0/lib/assets/javascripts
Extracted source (around line #329):
327
328
329
330

}

@import 'font-awesome-sprockets';
@import 'font-awesome';

我将不胜感激任何帮助。如果需要更多日志,请告诉我。

1 个答案:

答案 0 :(得分:1)

gem 'font-awesome-sass', '~> 4.4.0'添加到Gemfile忘记bundle install后,似乎bundle install它会解决您的问题

注意:您无需<link rel="stylesheet" href="css/application.css">即可删除它。