HappyCry
HappyCry

Reputation: 893

Rails assets not compiling when pushing to production

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.

Upvotes: 4

Views: 2766

Answers (3)

Raza Hussain
Raza Hussain

Reputation: 762

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

Upvotes: 1

Tim Brice
Tim Brice

Reputation: 1

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.

Upvotes: 0

Richard Peck
Richard Peck

Reputation: 76784

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

Upvotes: 2

Related Questions