5

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

我的宝石文件有这些宝石包括

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

我也包括在我的application.css文件*= require bootstrap_and_overrides。我知道,链轮编译每个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; 

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

更新我的资产宝石集团

# 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 
+0

你在你的资产组少护栏宝石? – Swift

+0

我这样做,更新了我的宝石资产组的问题 –

回答

6

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

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值或类似的东西..

+0

以上补丁无效,因为'sass'不是'config'的属性。我得到这些错误:'/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/railtie/configuration.rb:85:in method_missing:undefined method sass for#(NoMethodError)' –

+1

我在最后一篇文章中删除了模块和类包装器。正确编辑示例。 – shigeya

+0

感谢您分享您的方法,尽管我在部署之前通过在本地运行'rake assets:precompile'来解决了我的问题,并且所有内容都得到了修复。 –

0

我使用较少的引导与轨道4.1和2.0红宝石,但我通过增加固定这这application.css.scss

*= require_tree . 
*= require bootstrap_and_overrides 
*= require_self 
相关问题