Rails Engine-找不到要导入的文件或不可读:font-awesome [英] Rails Engine - File to import not found or unreadable: font-awesome

查看:84
本文介绍了Rails Engine-找不到要导入的文件或不可读:font-awesome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个超级简单的Rails应用程序,并且使用字体很棒,没有问题.将其扩展为在Rails引擎中执行相同的步骤会产生以下错误.

I did a super simple rails app and used font-awesome with no problem. Expanding this to do the same steps in a rails engine produces the following error.

File to import not found or unreadable: font-awesome

我找不到解决方案.如果有人对如何使这种简单的Rails引擎与font-awesome兼容,我将不胜感激.

I am unable to find a solution. If anyone has suggestions on how to make this simple rails engine work with font-awesome, I would be most appreciative.

使用一个模型类创建基本引擎以进行测试

rails plugin new testeng --full --mountable 
cd testeng
bundle install
rails g scaffold book title:string desc:string
rake db:migrate

添加超赞的字体

编辑testeng.gemspec并在包含rails gem之后添加sass-rails和font-awesome gems

edit testeng.gemspec and add sass-rails and font-awesome gems after the rails gem is included

  s.add_dependency 'sass-rails', '~> 4.0.3'
  s.add_dependency 'font-awesome-rails'

将application.css重命名为application.css.scss

rename application.css to application.css.scss

cd app/assets/stylesheets/testeng/
mv application.css application.css.scss

编辑app/assets/stylesheets/testeng/application.css.scss并在文件末尾附加导入语句.

edit app/assets/stylesheets/testeng/application.css.scss and append import statement at end of file.

@import 'font-awesome';

编辑app/views/testeng/books/index.html.erb并使用一些超棒的字体图标

edit app/views/testeng/books/index.html.erb and use some font-awesome icons

<h1>Listing books</h1>

<%= link_to content_tag(:i, '', :class => "fa fa-plus-circle"), new_book_path  %>

启动Rails服务器

cd <root-app-path>
bundle install
cd test/dummy
bundle install
rails s

在浏览器中测试

http://localhost:3000/testeng/books

获取错误

File to import not found or unreadable: font-awesome

推荐答案

改为安装font-awesome-sass:

Install font-awesome-sass instead:

gem 'font-awesome-sass', '~> 4.4.0'

捆绑它:

bundle install

将以下内容添加到application.css.scss(应用程序/资产/样式表):

Add the following to your application.css.scss (app/assets/stylesheets):

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

作为测试,您可以在视图中添加以下行以查看其是否有效:

As a test you can add the following line to your view to see if it works:

<%= icon('thumbs-up', 'It Worked!!!', id: 'my-icon', class: 'fa-5x') %>

这篇关于Rails Engine-找不到要导入的文件或不可读:font-awesome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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