【发布时间】:2014-04-20 09:13:07
【问题描述】:
您好,我一直在关注 Michael Hartl 关于开发 Rails 应用程序的书。我已经走到了尽头,我想开始在我开发的应用程序中使用 Bootstrap3。
我已按照https://github.com/twbs/bootstrap-sass 上的说明进行操作,但这并没有奏效。 gem 已正确安装,我可以通过更改我的 application.css --> application.css.scss 并将 import "bootstrap" 语句添加到文件中并将其放入 custom.css 中来使其在本地环境中工作。 scss。这似乎不对,当我部署到 Heroku 时它也不起作用。
我想要工作的设置如下。
宝石文件
source "http://rubygems.org"
ruby '2.0.0'
gem 'rails', '4.0.1'
gem 'sass-rails'
gem 'bootstrap-sass'
gem 'bcrypt-ruby', '3.1.2'
gem 'faker', '1.1.2'
gem 'will_paginate'
gem 'bootstrap-will_paginate'
gem 'sprockets', '2.11.0'
gem 'pg'
gem 'uglifier'
gem 'coffee-rails'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder'
group :development, :test do
gem 'rspec-rails'
gem 'guard-rspec'
gem 'spork-rails'
gem 'guard-spork'
gem 'childprocess'
end
group :test do
gem 'selenium-webdriver'
gem 'capybara'
gem 'growl'
gem 'factory_girl_rails', '4.2.1'
end
group :doc do
gem 'sdoc', require: false
end
group :production do
gem 'rails_12factor'
end
应用程序.css
/*
* 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_tree .
*/
custom.css.scss
@import "bootstrap";
/*mixins, variables etc. */
$grayMediumLight: #eaeaea;
@mixin box_sizing{
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
/* universal */
html {
overflow-y: scroll;
}
body {
padding-top: 60px;
}
...
...
理想情况下,我认为我应该将 application.css 更改为 .css.scss 并在那里导入引导程序,而我的 custom.css.scss 中也不需要它。这在部署到 Heroku 时会导致错误,即 application.css 已经是必需的。
更新
根据下面的建议,我已经删除了
Import "bootstrap";
来自 custom.css.scss 并将其添加到重命名的 application.css.scss 中。现在看起来像
@import "bootstrap";
@import "custom";
我清除了 tmp 文件夹使用
rake tmp:clear
然后刷新页面。
单独导入css.scss文件好像解决了我的问题
【问题讨论】:
-
如果我没记错的话,你必须导入
twitter/bootstrap。但是,如果您没有收到任何错误,那就很奇怪了。 -
我之前在我的应用程序上设置了 Bootstrap 2,这会影响它吗?我以为 gem 会为我安装引导程序,而无需我手动导入引导程序文件?
-
很抱歉,我的 cmets 对已弃用的 bootstrap sass 版本有效。
标签: css ruby-on-rails twitter-bootstrap heroku