2014-02-08 89 views
1

我想在我的rails(4.0.0)项目中使用bootstrap-sass(3.1.0.2)和sass-rails(4.0.1)。Bootstrap Sass with Rails 4

我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 vendor/assets/stylesheets of plugins, if any, 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 top of the 
* compiled file, but it's generally better to create a new file per style scope. 
* 
*= require_self 
*= require font-awesome 
*= require_tree . 
*/ 

我bootstrap_and_overrides.css.scss文件是在样式表文件夹,如下所示:

@import "bootstrap"; 

我有一个测试页面设置试试这个:

<div class="container"> 
<h2>test terms</h2> 
<h1>h1. Bootstrap heading <small>Secondary text</small></h1> 
<p class="bg-primary">.dfd..</p> 
<p class="bg-success">..sdfas.</p> 
<p class="bg-info">..sdfs.</p> 
<p class="bg-warning">.asdf..</p> 
<p class="bg-danger">.adf..</p> 
<p>test terms</p> 


<button type="button" class="btn btn-primary">Default</button> 

</div> 
<button type="button" class="btn btn-info">Info</button> 

当我启动服务器并访问该页面时,它重新纯文本没有引导样式的nders。

任何想法做什么,将不胜感激。看来这里有几个人不使用宝石。这种方法有什么理由吗?非常感谢!

+0

可否请您发布html页面的来源?它可能有一些信息。如果可能的话,也是布局文件 – Muntasim

+0

您是否运行'捆绑包'? –

+0

您是否尝试过在application.css.scss中需要引导程序?或者尝试在conflig/application.rb中添加require(第二种方法,第一种方法返回错误) –

回答

0

这里是我的设置与https://github.com/twbs/bootstrap-sass

# Gemfile 
gem 'bootstrap-sass' 

# application.css.scss 
/* 
*= require_self 
*= require vendor 
* require_tree . 
*/ 

@import "bootstrap"; 

// Import individual stylesheet 
@import "base"; /* app/assets/stylesheets/base.css.scss */ 
@import "events"; /* app/assets/stylesheets/events.css.scss */ 

require_tree .被禁用,但不是导入单个CSS文件(baseevents)。

+0

嗨,维克多,感谢您的分享。我想知道css行为的顺序是否重要。我在样式表文件夹中的一个单独的文件中导入了引导程序,该文件夹被该树拾取。我已经尝试过你的设置,并没有任何运气,但会尝试创建一个新项目 - 也许有其他地方的东西,导致它不工作。非常感谢答复。 – Mel

+0

是的,CSS导入的顺序很重要。在我的情况下,如果在我的'''events.css.scss'中我的'base.css.scss'中有'body {background:white}',并且'body {background:red}','body''background '会变成'红色',因为后者会覆盖前面的CSS。使用https://github.com/twbs/bootstrap-sass – Victor

+0

非常感谢。 – Mel

5

几天前我面临几乎相同的问题。我的配置完全相同,但Bootstrap的几个样式效果不起作用(尤其是bg-whatever-color)。几次更新后,问题消失。

我的一些宝石,我更新

gem 'rails', '4.0.3' 
gem "bootstrap-sass", "~> 3.1.1.0" 
gem 'font-awesome-sass' 
gem 'sass-rails', '~> 4.0.0' 

不要忘了:我application.scss的

bundle update 

部分给你一个想法

*= require jquery.ui.all 
*= require select2 
*= require font-awesome 
*/ 

@import "mixin_and_var"; 
// changing the breakpoint value before importing bootstrap style 
// This change is made for the menu (navbar) to collapse on tablet for better view 
$screen-sm:1024px; 
@import "bootstrap"; 

@import "general_layout"; 
@import "header"; 
@import "footer"; 
@import "menus"; 
@import "pagination"; 
@import 'login'; 
@import "error"; 

希望它有助于!