带有Bootstrap的Rails(在Windows上) - 空的application.css文件和样式不会加载

时间:2017-03-08 09:05:38

标签: ruby-on-rails windows ruby-on-rails-5 twitter-bootstrap-rails

enter image description here

GemFile的相关部分:

enter image description here


捆绑安装:

enter image description here


仍然没有效果:

enter image description here


来自\ app \ views \ layouts \ application.html.erb:



<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
&#13;
&#13;
&#13;

的application.js:

&#13;
&#13;
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require turbolinks
//= require_tree .
&#13;
&#13;
&#13;

如何加载Bootstrap样式?

2 个答案:

答案 0 :(得分:0)

似乎缺少导入引导程序样式。要根据bootstrap-sass documentation解决此问题,您应该:

app/assets/stylesheets/application.scss

中导入Bootstrap样式
// "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables"
@import "bootstrap-sprockets";
@import "bootstrap";
必须在引导程序之前导入

bootstrap-sprockets才能使图标字体生效。

确保文件的扩展名为.scss(或Sass语法为.sass)。如果你刚刚生成了一个新的Rails应用程序,它可能会附带一个.css文件

答案 1 :(得分:0)

首先,您应该决定使用哪个宝石,twitter-bootstrap-railsbootstrap-sass,而不是两者。

假设您使用bootstrap-sass,那么application.js应该

//= require bootstrap-sprockets

不是

//= require twitter/bootstrap

然后添加

@import "bootstrap-sprockets";
@import "bootstrap";

到你的app/assets/stylesheets/application.scss R. Sierra说。

现在你的应用程序应该不错!