[英]Rails 5 with Font-Awesome and Bootstrap error
I'm building my first rails application, and I'd like to integrate both bootstrap and font-awesome. 我正在构建我的第一个Rails应用程序,并且想要集成bootstrap和font-awesome。 I managed to get the application working properly using just bootstrap, but when I attempted to incorporate font-awesome as well, I either get the error: file to import not found or unreadable:font-awesome, or the webpage shows up, but only renders using just html, without any of the css or bootstrap styling that I've added.
我设法仅使用引导程序就使应用程序正常运行,但是当我也尝试合并字体真棒时,我遇到了错误:找不到导入文件或文件不可读:字体真棒,或者只显示了网页仅使用html进行渲染,而无需添加任何CSS或Bootstrap样式。 I then simply decided not to use font-awesome, but after attempting to remove it, the application just renders with just the html, and none of the added bootstrap styling.
然后,我只是简单地决定不使用超棒的字体,但是在尝试将其删除后,该应用程序仅使用html进行渲染,并且未添加任何引导样式。
Here is my application.css.scss: 这是我的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";
I searched through some other issues that were similar to this one - I saw that for rails engines, if you did @import "font-awesome.css" that seemed to work. 我搜索了与此类似的其他问题-我发现对于Rails引擎来说,如果您执行@import似乎有效的“ font-awesome.css”,我会发现。 However, I'm not building a rails engine, and attempting this did not resolve the issue.
但是,我没有构建Rails引擎,尝试这样做不能解决问题。
I've included gem 'font-awesome-rails' in my gemfile, and ran a bundle install as well. 我在gemfile中包含了gem'font-awesome-rails',并且还运行了捆绑安装。
Lastly, I'm using rails 5.0.0.1, and font-awesome-rails 4.7.0.0 最后,我正在使用rails 5.0.0.1和font-awesome-rails 4.7.0.0
Any ideas what is wrong? 任何想法有什么问题吗? Any help would be much appreciated
任何帮助将非常感激
Add in Gemfile: 在Gemfile中添加:
gem 'bootstrap-sass', '~> 3.3.6'
gem 'font-awesome-sass', '~> 4.7.0'
And then bundle install
然后
bundle install
Create a file in /app/assets/stylesheets/bootstrap_overrides.css.scss
and add this line:- 在
/app/assets/stylesheets/bootstrap_overrides.css.scss
创建一个文件,并添加以下行:
@import "bootstrap-sprockets";
@import "bootstrap";
@import "font-awesome-sprockets";
@import "font-awesome";
Example to use font awesome, in the view: 在视图中使用超棒字体的示例:
<%= icon('flag') %>
Please check the link for more usages on font awesome 请检查链接以获取更多有关真棒字体的用法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.