4

I am trying to deploy my rails app to production and I'm trying to precompile all of the assets:

My assets.rb file:

Rails.application.config.assets.precompile += %w( *.css.sass )
Rails.application.config.assets.precompile += %w( *.css.scss )
Rails.application.config.assets.precompile += %w( *.css )
Rails.application.config.assets.precompile += %w( *.js )
Rails.application.config.assets.precompile += %w( *.js.coffee )
Rails.application.config.assets.precompile += %w( *.js.coffee.erb )

However, when I try to deploy using capistrano, I get the following error:

DEBUG[c79c6191]     rake aborted!
DEBUG[c79c6191]     Sass::SyntaxError: Undefined variable: "$alert-padding".

In my assets.rb file before, I had added each asset individually file by file, and the deploy was working, however, I am importing some assets in the layout file:

<%= javascript_include_tag 'application', 'jquery-ui-1.9.2', 'js-example', 'js-example2', 'data-turbolinks-track' => true %>

But I am also importing some using sprockets:

//= require jquery
//= require bootstrap-sprockets
//= require angular
//= require jquery_ujs
//= require turbolinks
//= require_tree .

This method was working well while I was developing the app, but when I deploy the app to production, it seems like stuff that I am importing using sprockets is not being imported (i.e. Angular)

Thanks in advance.

EDIT: As requested, my application.css.scss file:

/*
 *
 *= require_tree .
 *= require_self
 */

@import "bootstrap-sprockets";
@import "bootstrap";
@import "font-awesome";

EDIT2: I also followed this method: bootstrap-sass: Undefined variable: "$baseLineHeight", but I need it to precompile all of the assets.

Community
  • 1
  • 1
HappyCry
  • 873
  • 2
  • 9
  • 16
  • 2
    It says you have a problem in one of your sass files, the variable $alert-padding is not defined. – Marc Lainez Aug 19 '14 at 14:23
  • But the file it points to is: (in /home/deploy/app/shared/bundle/ruby/2.1.0/gems/bootstrap-sass-3.2.0.1/assets/stylesheets/bootstrap/_alerts.scss:10), which is a bootstrap file? – HappyCry Aug 19 '14 at 14:27
  • could it be that the order that you are compiling is wrong? since $alert-padding is undefined that would imply that you don't have that function at the build process. But if you did include the package that defined it then the build call order should be looked into. – lifejuggler Aug 19 '14 at 14:29
  • We need more details, show us the content of your application.css and make sure you followed these instructions https://github.com/twbs/bootstrap-sass – Marc Lainez Aug 19 '14 at 14:29
  • @mlainez - I've added the application.css.scss file. – HappyCry Aug 19 '14 at 14:42
  • @lifejuggler - what order should i precompile, I'm assuming the assets.rb file dictates the order in which the compile is occurring, I tried to shift the *.css up, but it didn't work. – HappyCry Aug 19 '14 at 14:43
  • What happens if you try to precompile your assets in development mode? Does it fail as well? rake assets:precompile – Marc Lainez Aug 19 '14 at 15:07
  • did you manage to fix it? – dima May 05 '15 at 12:32

3 Answers3

2

Here's your error:

Sass::SyntaxError: Undefined variable: "$alert-padding".

The likely cause of this is bootstrap that you've included in the top of the file:

//= require bootstrap-sprockets

--

SCSS

I would suggest the problem is either that you're not calling the file with the SCSS preprocessor, or that there's something wrong with the bootstrap gem you're calling

Having looked around online, I would recommend the following:

#app/assets/stylesheets/application.css.scss
@import "bootstrap-sprockets", "bootstrap";

--

Precompile

I would remove all the calls from your assets.rb file:

Rails.application.config.assets.precompile += %w( *.css.sass )
Rails.application.config.assets.precompile += %w( *.css.scss )
Rails.application.config.assets.precompile += %w( *.css )
Rails.application.config.assets.precompile += %w( *.js )
Rails.application.config.assets.precompile += %w( *.js.coffee )
Rails.application.config.assets.precompile += %w( *.js.coffee.erb )

All of these are called anyway - you don't need to reaffirm them in the assets.rb initializer

Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • But I need //= require bootstrap-sprockets in the application.js to import the bootstrap js components. Also if I get rid of the precompile stuff from assets.rb, I get the error: "Asset filtered out and will not be served: add `Rails.application.config.assets.precompile += %w( admin-styles.css )` to `config/initializers/assets.rb` and restart your server" – HappyCry Aug 19 '14 at 14:52
  • 1
    The configuration I have set up right now works perfectly in the development environment, but I need it to work in production. – HappyCry Aug 19 '14 at 14:52
1

I had the same problem and I fixed it by removing

Rails.application.config.assets.precompile += %w( *.css )

above line from initializers/assets.rb

I hope this will help some one

Raza Hussain
  • 762
  • 8
  • 18
0

What version of sprockets are you using? I had a similar issue and had to use 2.11.0 to get it to work correctly. I think there is some sort of issue using bootstrap and the latest version of sprockets.