使用 bootstrap-sass gem 处理一个从 Bootstrap 2.3 开始的项目,在我的 gemfile 中指定版本 2.3.1.0。我想将其更新为 Bootstrap 3。
这是应用程序在 bootstrap-sass gem 版本 2.3.1.0 中的样子:
我检查了一个分支以尝试将样式更新为 Bootstrap 3,因此我更新了我的 gemfile 以使用最新版本的 bootstrap-sass gem,运行包更新并安装。
我在上面看到的每个“惊人点”div 元素上都有引导 3 个版本类,所以英雄单元中的样式应该消失,按钮应该变平,惊人点应该跨越 4 列,并带有“col-lg” -4" 我指定的类。
但是当我启动 rails 服务器时,我得到了 Bootstrap 2.3 和 3 的混合:
“col-lg-4”类应用于惊人点,但登录和注册按钮仍然看起来像 Bootstrap 2.3 按钮!“登录”和“注册”文本中有一个微妙但明显的变化——它有点粗体。这就像我有一些奇怪的 Bootstrap 2.3 和 3 的混合体。
但现在我运行 rake assets:precompile,得到的结果如下:
现在事情正在正确显示。
但是为什么我总是必须运行 rake assets:precompile 才能使其正常工作?当我在 gem 文件之间切换时,如何让它自动更新?
以下是其他相关文件:
应用程序.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 bootstrap
*= require_tree .
*/
宝石文件:
source 'https://rubygems.org'
gem 'rails', '3.2.13'
gem 'jquery-rails'
gem 'devise'
group :production do
gem 'pg'
end
group :development do
gem 'sqlite3'
end
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'bootstrap-sass', '3.0.2.0'
end
Gemfile.lock(我只展示 bootstrap-sass 版本):
bootstrap-sass (3.0.2.0)
sass (~> 3.2)
应用程序.rb:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
module Bloccit
class Application < Rails::Application
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
config.active_record.whitelist_attributes = true
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
config.assets.initialize_on_precompile = false
end
end
config/development.rb 中的相关行:
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
config.assets.compile = true
config.serve_static_assets = false