简体   繁体   English

Bootstrap Sass与Rails 4

[英]Bootstrap Sass with Rails 4

I'm trying to use bootstrap-sass (3.1.0.2) and sass-rails (4.0.1) in my rails (4.0.0) project. 我正在尝试在我的rails(4.0.0)项目中使用bootstrap-sass(3.1.0.2)和sass-rails(4.0.1)。

My application.css.scss file looks like this: 我的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 .
*/ 

My bootstrap_and_overrides.css.scss file is in the stylesheets folder and looks like this: 我的bootstrap_and_overrides.css.scss文件位于stylesheets文件夹中,如下所示:

@import "bootstrap";

I have a test page set up to try it out with this: 我设置了一个测试页面来尝试使用此页面:

    <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>

When I start the server and visit the page, it renders in plain text without the bootstrap styling. 当我启动服务器并访问该页面时,它以纯文本形式呈现,而没有引导样式。

Any ideas on what to do would be appreciated. 任何想法做什么都将不胜感激。 It seems a few people on here don't use the gems. 似乎这里有些人不使用宝石。 Is there a reason for this approach? 有这种方法的原因吗? Thanks very much! 非常感谢!

I faced nearly the same problem few days ago. 几天前我遇到了几乎相同的问题。 My configuration was quite the same but only few styling effects of Bootstrap were not working (especially the bg-whatever-color). 我的配置完全相同,但是Bootstrap的样式效果很少(特别是bg-whatever-color)。 After few gems updated the problem disappear. 几个宝石更新后,问题消失了。

Some of my gems that I updated 我更新的一些宝石

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

Don't forget the: 不要忘记:

bundle update

Part of my application.scss to give you an idea 我的application.scss的一部分,为您提供一个想法

*= 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";

Hope it helps! 希望能帮助到你!

Here's my setup with https://github.com/twbs/bootstrap-sass : 这是我使用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 . is disabled, but importing individual CSS files ( base , events ) instead. 已禁用,但是导入单个CSS文件( baseevents )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM