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 
相關問題