5

我正在使用 bootstrap-rails gem 的最新主分支,并尝试以与 rails 资产管道兼容的方式修改默认引导变量。

我的 gem 文件包含这些 gem

gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
gem 'uglifier', '>= 1.0.3'
gem 'less-rails-bootstrap'

我也包含*= require bootstrap_and_overrides在我的application.css文件中。我知道 sprockets 会单独编译每个 css 文件,因此您不能期望多个 css 文件能够相互引用。因此 bootstrap_and_overrides.css.less 文件包括以下内容:

@import "twitter/bootstrap/bootstrap";
body { padding-top: 80px; }

//background-image: asset-url("background.png"); background-repeat:no-repeat; background-size: cover;  }

@import "twitter/bootstrap/responsive";

// Set the correct sprite paths
@iconSpritePath: asset-path('twitter/bootstrap/glyphicons-halflings.png');
@iconWhiteSpritePath: asset-path('twitter/bootstrap/glyphicons-halflings-white.png');

// Set the Font Awesome (Font Awesome is default. You can disable by commenting below lines)
@fontAwesomeEotPath: asset-path('fontawesome-webfont.eot');
@fontAwesomeWoffPath: asset-path('fontawesome-webfont.woff');
@fontAwesomeTtfPath: asset-path('fontawesome-webfont.ttf');
@fontAwesomeSvgzPath: asset-path('fontawesome-webfont.svgz');
@fontAwesomeSvgPath: asset-path('fontawesome-webfont.svg');

// Font Awesome
@import "fontawesome";

// Your custom LESS stylesheets goes here
//
// Since bootstrap was imported above you have access to its mixins which
// you may use and inherit here
//
// If you'd like to override bootstrap's own variables, you can do so here as well
// See http://twitter.github.com/bootstrap/less.html for their names and documentation
//
// Example:
// @linkColor: #ff0000;

@navbarHeight: 60px;
@navbarText: @white;
@textColor: @orange;
@navbarLinkColor: @white;
@navbarBackground: darken(@linkColor, 15%);
@navbarBackgroundHighlight: @linkColor;

但是,我的覆盖都没有在资产管道下工作。没有它他们工作得很好。有谁知道为什么?

更新我的资产 Gem Group

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'less-rails'
  #  gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  gem 'therubyracer', :platform => :ruby
  gem 'uglifier', '>= 1.0.3'
end
4

3 回答 3

6

在部署之前在本地运行rake assets:precompile解决了我上面的问题。

于 2012-05-09T01:08:51.767 回答
3

在我的情况下,资产管道引擎寻找资源的目录没有正确设置,导致资产没有正确编译。

我正在使用 bootstrap-sass,所以你的情况可能会有所不同。但就我而言,将以下代码添加到 application.rb 解决了我的问题。

module ApplicationModuleName
  class Application < Rails::Application

    config.sass.load_paths = []
    config.sass.load_paths << "#{Rails.root}/app/assets/stylesheets"
    %w(bootstrap-sass jstree-rails jquery-rails).each do |pkg|
      config.sass.load_paths << "#{Gem.loaded_specs[pkg].full_gem_path}/vendor/assets/stylesheets"
      config.assets.paths << "#{Gem.loaded_specs[pkg].full_gem_path}/vendor/assets/javascripts"
    end
  end
end

在应用上述(丑陋的)补丁之前,请尝试运行rails console并检查值load_paths或类似的东西..

于 2012-05-07T05:03:10.213 回答
0

我在 rails 4.1 和 ruby​​ 2.0 中使用较少的引导程序,但我通过将其添加到 application.css.scss 来解决这个问题

*= require_tree .
*= require bootstrap_and_overrides
*= require_self
于 2014-02-24T17:12:19.627 回答