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

时间:2013-11-08 18:43:28

标签: ruby-on-rails twitter-bootstrap bootstrap-sass

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

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

enter image description here

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

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

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

enter image description here

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

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

enter image description here

现在事情正确显示。

但为什么我总是要运行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

1 个答案:

答案 0 :(得分:0)

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

出于某种原因,如果你从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。< / p>

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