skip to Main Content

I got stuck on production environment for rails application because my assets are not compiled. When I use

rvmsudo bundle exec rake assets:precompile RAILS_ENV=production --trace

It throws rake aborted! Sass::SyntaxError: Undefined variable: "$alert-padding"

Here is my Gemfile:

            source ''
            gem 'rails', '4.2.3'
            gem 'mysql2', '~> 0.3.11'
            gem 'jquery-rails'
            gem 'jquery-ui-rails'
            gem 'sass-rails', '~> 5.0'
            gem 'bootstrap-sass', '~> 3.2.0'
            gem 'uglifier', '>= 1.3.0'
            gem 'coffee-rails', '~> 4.1.0'
            gem 'jbuilder', '~> 2.0'
            gem 'sdoc', '~> 0.4.0',          group: :doc
            gem 'haml'
            gem 'haml-rails'
            gem 'devise', github: 'plataformatec/devise'
            gem 'html2haml'
            gem 'simple_form'
            gem 'validates_formatting_of'
            gem 'tzinfo-data'
            gem 'therubyracer',  platforms: :ruby
            gem 'twitter-bootstrap-rails'
            gem 'jquery-validation-rails'
            gem 'sprockets-rails', :require => 'sprockets/railtie'
            gem 'jquery-turbolinks'

            gem 'paperclip'
            gem 'fancybox-rails'
            gem 'css3-progress-bar-rails'

            group :development do
              gem 'spring'
              gem 'pry-rails'
              gem 'better_errors'

            group :development, :test do
              gem 'rspec-rails'
              gem 'factory_girl_rails'

            gem 'delayed_job_active_record'

            # Need daemons to start delayed_job
            gem 'daemons'

            gem 'rails_config', '~> 0.4.2'
            gem 'cancan'
            gem 'two_factor_authentication'
            gem 'twilio-ruby'
            gem 'binding_of_caller'
            gem 'rest-client'

Here is my porduction.rb

  Rails.application.configure do
      config.cache_classes = true
      config.eager_load = true
      config.consider_all_requests_local       = false
      config.action_controller.perform_caching = true
      config.serve_static_files = true
      config.assets.js_compressor = :uglifier
      config.assets.css_compressor = :sass
      config.assets.compile = false
      config.assets.compress = false
      config.assets.digest = true
      config.log_level = :debug

      config.action_mailer.perform_deliveries = true
      config.action_mailer.delivery_method = :smtp
      config.action_mailer.raise_delivery_errors = true
      config.i18n.fallbacks = true
      config.active_support.deprecation = :notify
      config.action_mailer.default_url_options = { :host => Settings.PROD_URL }
      config.log_formatter =
      config.active_record.dump_schema_after_migration = false

And application.css:

    *= require_tree .
    *= require_self

So, why i am getting rake aborted! Sass::SyntaxError: Undefined variable: "$alert-padding" while compiling.
My production works but no css is loaded to it.



  1. $alert-padding variable is used before being defined. It may be caused by a wrong order of css files in application.css. require_tree loads all files from the current folder in alphabetical order (I guess), but you need some styles to loaded in specific order.

    It seems like you’re using bootstrap-sass gem. Consider the following instruction from the gem’s README: You need to rename application.css to application.scss and use @import instead of require.

    Login or Signup to reply.
  2. With SASS you have to include your variables before they’re called.

    Dir globbing / Sprockets include files alphabetically:

    This has the problem that files are required alphabetically. If your directory has jquery-ui.js and jquery.min.js then Sprockets will require jquery-ui.js before jquery is required which won’t work (because jquery-ui depends on jquery).

    This means if you’re using a variables.sass (or similar), you’ll want to either rename it, or include it explicitly:

       *= require variables
       *= require_tree .
       *= require_self
       *= stub variables

    Even better (since you’re using SASS), use the @import directive:

    @import variables
    @import *
    Login or Signup to reply.
  3. I had a same issue
    I just added this two lines in environment/production.rb

    config.assets.compile = true
    config.assets.precompile += %w( active_admin.css.scss )

    It works for me.

    Login or Signup to reply.
  4. Just add these lines in your config/application.rb if you are using scss instead of css.

    config.assets.precompile << %w( *.scss *.js )
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top