17

I've integrated bootstrap into my app using bootstrap-sass. The app works fine on my local machine, but when I go to deploy via capistrano, I get this error:

Undefined variable: "$baseLineHeight".
(in /var/www/CollegeSportsBlueBook/shared/bundle/ruby/1.9.1/gems/bootstrap-sass-2.0.1/vendor/assets/stylesheets/bootstrap/_accordion.scss)

When the capistrano attempts to run assets:precompile

I think this variable is throwing the error because it is the first variable in the first scss file that is attempted to be precompiled.

Something isn't loading up right. Any ideas what it might be?

Edit

Full trace here https://gist.github.com/2233071

Edit 2

Added application.rb and production.rb to gist

nobody
  • 1,782
  • 17
  • 28
Tyler DeWitt
  • 23,366
  • 38
  • 119
  • 196
  • Can you run `rake assets:precompile` on your localmachine? – stephenmurdoch Mar 28 '12 at 21:56
  • Yea, but I have to run it and specify that I am on the development environment, if that matters: `RAILS_ENV=development bundle exec rake assets:precompile` – Tyler DeWitt Mar 28 '12 at 22:09
  • Have you changed `config.assets.precompile` at all? – nobody Mar 29 '12 at 16:17
  • @ThomasMcDonald - I don't think so. I added application.rb and production.rb to the gist. If you don't mind checking them out and making sure things look right. Thanks. – Tyler DeWitt Mar 29 '12 at 17:05
  • @TylerDeWitt Yeah, you have changed it. Let me throw an answer together. – nobody Mar 29 '12 at 17:52
  • @ThomasMcDonald I saw on github someone else was able to get things working with the 2.0.2 branch. Should I try that or is there a fix in my `config.assets.percompile` you'd like me to try first? – Tyler DeWitt Mar 29 '12 at 22:26
  • here i have given answer for it http://stackoverflow.com/questions/21911620/rails-bootstrap-sass-assets-compilation-error-undefined-variable-alert-padding/26998970#26998970 – Vinay Shankar Nov 18 '14 at 16:54

3 Answers3

55

You've edited your production.rb file so that Rails will attempt to precompile all CSS/JS files (line 48).

By default Rails will only precompile application.css(.scss). By adding the wildcard selector to config.assets.precompile you are asking Rails to precompile every css asset in your application, including Sass partials. Naturally, this is probably not the behaviour you wish for.

# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w( *.css *.js )

Rails will therefore iterate over each css asset, compiling them. It so happens that _accordion.css.scss is the first Bootstrap asset it comes across, and Rails will attempt to compile that first. _accordion isn't independent, and requires some files to be loaded before it, hence the error. It should never be compiled as a separate file anyway.

You need to change your config.assets.precompile to add only the additional files that you need aside from application.css/application.js.

nobody
  • 1,782
  • 17
  • 28
  • This was exactly my problem as well and your solution solved it and gave me a clear answer as to where I messed up. – cfeduke Apr 09 '12 at 16:13
  • 1
    I don't have `config.assets.precompile += %w( *.css *.js )` anywhere and am getting the exact same error. Any help would be appreciated. – kakubei Aug 29 '13 at 17:08
  • 2
    Thank you. Same here. In Rails 4.2.1, the file to modify is now in /config/initializers/assets.rb – Nick_K May 31 '15 at 22:38
1

Initially I had the similar problem Sass::SyntaxError: Undefined variable: "$alert-padding". problem with this line in the assets.rb file:

Rails.application.config.assets.precompile += [/.*\.css/] 

Don't know why but for me it helped to change it to this line

Rails.application.config.assets.precompile += [/^[-_a-zA-Z0-9]*\..*/]

After it the problem was solved and everything worked in production.

Seybo Glaux
  • 787
  • 1
  • 7
  • 16
1

You need to make sure the import of all your css is done in the proper order. For variables to work it needs to be one of the first few css files to be loaded.

This post/answer should help Proper SCSS Asset Structure in Rails

Community
  • 1
  • 1
Ben
  • 13,297
  • 4
  • 47
  • 68