8

新しい Rails 3.1 アプリを作成しました。Twitter ブートストラップ CSS ファイルを app/assets/stylesheets/bootstrap.min.css に追加しました。ここに関連するコードがあります

app/assets/stylesheets/application.css (ツリーが含まれているため、ブートストラップが含まれています)

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. 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_tree . 
*/

Gemfile (コンパイル/圧縮用の execjs と therubyracer を含む)

group :development, :qa do
  gem 'execjs'
  gem 'therubyracer'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.1.0'
  gem 'coffee-rails', '~> 3.1.0'
  gem 'uglifier', '>= 1.0.3'
end

次に、rake タスクを実行してアセットをプリコンパイルします

rake assets:precompile

これは次のエラーで失敗します

Invalid CSS after ".inputs-list li+": expected number or function, was "li"

その CSS はブートストラップ ファイルにあります (「.inputs-list li+li」はセレクターです)。

ただし、実行すると

rake assets:precompile RAILS_ENV=development

今では正常に動作します。ファイルを圧縮しないように config/environments/production.rb を変更すると、次のようになります。

config.assets.compress = false

その後、元のコマンドも機能します(開発環境を指定せずに)。

では、どうすればエラーを追跡できますか? 今のところ、圧縮をオフにするだけで生活できますが、明らかに何かがおかしいです。レイルズですか?スプロケット? ルビーレーサー?醜い?

4

2 に答える 2

6

ブートストラップをsassに変換し、アセットパイプラインに組み込むライブラリの1つを使用することをお勧めします。このようにしてJSを組み込み、ブートストラップがpreboot.scssファイルで使用する変数を変更し、組み込む機能を選択できます。また、bundlerを使用してアップグレードすることもできます。

私はbootstrap-sassを使用していますが、うまく機能します:https ://github.com/thomas-mcdonald/bootstrap-sass

于 2011-10-17T16:37:29.950 に答える
4

縮小されていないバージョンのBootstrapを使用してこれを修正しました。実行時にコンパイルされるrake assets:precompileので、問題はありません:)

于 2011-10-17T16:34:24.560 に答える