首页 文章

Rails 5带有Font-Awesome和Bootstrap错误

提问于
浏览
0

我正在构建我的第一个rails应用程序,我想集成bootstrap和font-awesome . 我设法使用引导程序使应用程序正常工作,但是当我尝试合并字体很棒时,我得到错误:导入未找到或不可读的文件:font-awesome,或者网页显示,但仅使用html渲染,没有任何我添加的CSS或引导样式 . 然后我决定不使用font-awesome,但在尝试删除它之后,应用程序只使用html呈现,而没有添加引导程序样式 .

这是我的application.css.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 other CSS/SCSS
 * files in this directory. Styles in this file should be added after the last require_* statement.
 * It is generally better to create a new file per style scope.
 *
 *= require_font-awesome
 *= require_self
 *= require_tree .
 */
@import "bootstrap-sprockets";
@import "bootstrap";
@import "bootstrap/theme";
@import "font-awesome";

我搜索了一些类似于这个问题的其他问题 - 我看到了对于rails引擎,如果你做了@import“font-awesome.css”似乎有效 . 但是,我没有构建一个rails引擎,尝试这个并没有解决问题 .

我在我的gemfile中包含了gem'font-awesome-rails',并且还运行了一个bundle install .

最后,我使用的是rails 5.0.0.1和font-awesome-rails 4.7.0.0

有什么想法有什么不对?任何帮助将非常感激

1 回答

  • 0

    添加Gemfile:

    gem 'bootstrap-sass', '~> 3.3.6'
    gem 'font-awesome-sass', '~> 4.7.0'
    

    然后 bundle install

    /app/assets/stylesheets/bootstrap_overrides.css.scss 中创建一个文件并添加以下行: -

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

    在视图中使用字体awesome的示例:

    <%= icon('flag') %>
    

    请查看链接以获取更多用法font awesome

相关问题