Bootstrap v4在Rails中安装问题

时间:2017-01-09 22:22:44

标签: ruby-on-rails

或者他们是?当我在任何bootstrap组件上使用inspect元素时,它从application.css获取CSS(而不是bootstrap本身)。我很确定我在安装时做错了,尽管我已经完成了几次指导。

忘记添加我使用Rails 4.2.6并使用以下宝石: https://github.com/twbs/bootstrap-rubygem#a-ruby-on-rails

这就是我的意思,例如btn类正在工作,但它们没有指向检查元素中的Bootstrap,而是指向application.css。此外,导航栏(来自getbootstrap.com的复制粘贴)可以工作到javascript下拉菜单但CSS已关闭。 enter image description here

的Gemfile

#Bootstrap V4 Alpha
gem 'bootstrap', '~> 4.0.0.alpha6'
* sprockets-rails (3.2.0)

application.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 styles
 * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
 * file per style scope.
 *
 */

 @import "bootstrap";

的application.js

// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
//= require bootstrap

2 个答案:

答案 0 :(得分:1)

application.js之后的//= require bootstrap文件中//= require jquery,因此文件将如下所示:

// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require bootstrap
//= require jquery_ujs
//= require turbolinks
//= require_tree .

重新启动rails server,更改将生效。

答案 1 :(得分:0)

仔细查看application.css文件的评论。

 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.

这就是为什么似乎所有的css都来自application.css,但是你要导入文件底部的bootstrap css ..