紹介チェーン:
これは、bootstrap-Rails gemの問題として報告されています: https://github.com/anjlab/bootstrap-Rails/issues/91
宝石
_gem 'sass-Rails', '>= 3.2' # sass-Rails needs to be higher than 3.2
gem 'bootstrap-sass', '~> 3.1.1'
_
インストール(アセットグループの外部および内部で試行)、application.css.scssには
_@import "bootstrap";
_
のみ。
_bundle exec rake assets:precompile
_を試行すると、次のエラーが発生します。
_rake aborted!
Undefined variable: "$alert-padding".
(in /home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/bootstrap-sass-3.1.1.0/vendor/assets/stylesheets/bootstrap/_alerts.scss)
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/bootstrap-sass-3.1.1.0/vendor/assets/stylesheets/bootstrap/_alerts.scss:10
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/script/variable.rb:49:in `_perform'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/script/node.rb:40:in `perform'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:298:in `visit_prop'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:37:in `visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:100:in `visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:53:in `map'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:53:in `visit_children'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:109:in `block in visit_children'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:121:in `with_environment'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:108:in `visit_children'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:37:in `block in visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:320:in `visit_rule'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:37:in `visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:100:in `visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:53:in `map'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:53:in `visit_children'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:109:in `block in visit_children'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:121:in `with_environment'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:108:in `visit_children'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:37:in `block in visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:128:in `visit_root'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:37:in `visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:100:in `visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:7:in `visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/root_node.rb:20:in `render'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/engine.rb:315:in `_render'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/engine.rb:262:in `render'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-Rails-3.2.6/lib/sass/Rails/template_handlers.rb:106:in `evaluate'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/tilt-1.3.7/lib/tilt/template.rb:77:in `render'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/context.rb:193:in `block in evaluate'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `each'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `evaluate'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/processed_asset.rb:16:in `initialize'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/base.rb:18:in `new'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/base.rb:18:in `block in build_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:270:in `circular_call_protection'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/base.rb:14:in `build_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:93:in `block in build_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/caching.rb:19:in `cache_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:92:in `build_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:169:in `find_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/index.rb:14:in `find_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/bundled_asset.rb:12:in `initialize'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/base.rb:22:in `new'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/base.rb:22:in `build_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:93:in `block in build_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/caching.rb:19:in `cache_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:92:in `build_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:169:in `find_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/index.rb:14:in `find_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/static_compiler.rb:41:in `block in compile'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:219:in `block in each_logical_path'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:206:in `block (2 levels) in each_file'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in `each'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in `each_entry'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:204:in `block in each_file'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in `each'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in `each_file'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:217:in `each_logical_path'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/static_compiler.rb:29:in `compile'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/tasks/assets.rake:108:in `internal_precompile'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/tasks/assets.rake:115:in `block (3 levels) in <top (required)>'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/bin/rake:33:in `<top (required)>'
/home/joe/.rbenv/versions/1.9.3-p448/bin/rake:23:in `load'
/home/joe/.rbenv/versions/1.9.3-p448/bin/rake:23:in `<main>'
_
_/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/bootstrap-sass-3.1.1.0/vendor/assets/stylesheets/bootstrap.scss
_が実際にその下の_variables.scssファイルを_bootsrap/
_ディレクトリに最初にインポートすることを確認しました(_alerts.scssの前など)... _variables.scssで$を定義していますalert_padding。
_environments/production.rb
_ファイルで、アセットに関するすべてをコメントアウトし、マニュアル_config.assets.initialize_on_precompile = true
_に従って_https://github.com/twbs/bootstrap-sass
_だけを試してみました
environments/production.rb
_のアセットに関連する行をコメントアウトする、gemのページ(手動)_config.assets.initialize_on_precompile = true
_の1つだけにコメントするなど、さまざまな変更宝石のコンテンツを私のアセットディレクトリにコピーしました。これは基本的にjlongのbootstrapが行ったことです。
それは_application.css.scss
_を見ていない...私がそこに置いたものを無視し、代わりにフォルダを調べてそれらのファイルをロードすることを選択した。そのため、alerts.scssが最初に表示されます。 _variables.scssの名前を_aavariables.scssに変更してみたが、役に立たなかった
私の特定の問題は、application.rb
...に隠れているコードであることが判明しました...
私はputs config.assets.precompile.inspect
をconfig/environments/production.rb
に追加し、それが出力する正規表現に驚嘆しました。次に、コードベースで「config.assets.precompile」を検索したところ、application.rbに次のように表示されました。
config.assets.precompile << /(^[^_\/]|\/[^_])[^\/]*$/
...
config.assets.precompile += ["*.js", "*.css", "jquery-migrate-Rails.js"]
これが問題の原因でした。 (私はそれらの正規表現をトリプルチェックし、それらが_alerts.scssを取得するべきではないので少し戸惑っています...しかし、それを理解し、それらの行を削除することで修正されるという事実に焦点を当てます)
多分これは誰かを助けるでしょう...
理由はわかりませんが、私にとってはassets.rb
この行
Rails.application.config.assets.precompile += [/^[-_a-zA-Z0-9]*\..*/]
最初はSass :: SyntaxError:Undefined variable: "$ alert-padding"。problemがこの行にありました
Rails.application.config.assets.precompile += [/.*\.css/]
しかし、それを最初のものに変更した後、問題は解決され、すべてが本番環境で機能しました。
アセットのグロビングとプリコンパイルに問題があります。 https://github.com/twbs/bootstrap-sass/issues/86
Jsおよびcssアセットをプリコンパイルする必要がある場合:
Rails.application.config.assets.precompile += [proc { |filename, path| path =~ /(app|lib|vendor)\/assets/ && ['.js', '.css'].include?(File.extname(filename)) }]
基本的に、このプロシージャは、アセットのアプリライブラリとベンダーフォルダを検索します。
また、このコードを思いつくために Rails Guide のセクションを使用しました
私はRails 4.で同じ問題に直面していました。gems
を上書きする解決策を見つけました。そのため、bootstrap gem bootstrap-sass-X.X.X.X
vendors
フォルダー内の変更より、gemパスのGemfile
内の変更
gem 'bootstrap-sass', '3.3.1.0', :path => 'vendor/bootstrap-sass-X.X.X.X'
than write these 2 line
@import "bootstrap/variables";
@import "bootstrap/mixins";
at top of each of file which are inside the bootstrap folder
(vendor/bootstrap-sass-X.X.X.X/assets/stylesheets/bootstrap)
//like for _alerts.scss
// Alerts
// --------------------------------------------------
@import "bootstrap/variables";
@import "bootstrap/mixins";
// Base styles
// -------------------------