运行rake资产:在bootstrap gem版本之间来回切换时进行预编译?

使用bootstrap-sass gem开始使用Bootstrap 2.3开始的项目,在我的gemfile中指定版本2.3.1.0。 我想将它更新为Bootstrap 3。

这是使用bootstrap-sass gem version 2.3.1.0的应用程序的样子:

在此处输入图像描述

我检查了一个分支,试验将样式更新为Bootstrap 3,所以我更新了我的gemfile以使用最新版本的bootstrap-sass gem,运行bundle update并安装。

我在上面看到的每个“神奇点”div元素上都有bootstrap 3版本类,所以英雄单元中的样式应该消失,按钮应该变平,并且惊人的点应该跨越4列“col-lg” -4“我已经指定了。

但是当我启动rails服务器时,我得到了Bootstrap 2.3和3的混合:

在此处输入图像描述

“col-lg-4”类应用于Amazing Points,但登录和注册按钮仍然看起来像Bootstrap 2.3按钮! “登录”和“注册”文本中有一个微妙但可见的变化 – 它更加大胆。 这就像我有一些奇怪的Bootstrap 2.3和3的混合。

但现在我运行rake资产:预编译,这就是我得到的:

在此处输入图像描述

现在事情正确显示。

但为什么我总是要运行rake资产:预编译以使其正常工作? 当我在gem文件之间切换时,我怎么能把它自动更新?

以下是其他相关文件:

application.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 . */ 

的Gemfile:

 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) 

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

好的,所以我相信在查看这篇博文后我已经想到了一些。

出于某种原因,如果您从Bootstrap 2.3 bootstrap-sass gem版本更新到最新版本,您必须清除旧的bootstrap-sass gem。

所以我运行了gem list bootstrap-sass ,它给了我:

 *** LOCAL GEMS *** bootstrap-sass (3.0.2.0) bootstrap-sass (2.3.1.0) 

运行gem cleanup bootstrap-sass -d ,您将看到将要发生的事情。 然后运行gem cleanup bootstrap-sass -v ,它将卸载所有以前的版本。 重新启动rails服务器,它可以工作。

然后,如果你想回到旧的bootstrap-sass版本,你需要更新你的gemfile,运行bundle,然后运行gem uninstall bootsrap-sass 3.0.2.0或者你以后的任何bootstrap-sass gem。

这是一种痛苦,所以如果有人知道更好的方法,请分享。 我可能会看看bootstrap-sass-rails gem是否提供了更好的体验。