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 'https://rubygems.org'
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'
end
group :development, :test do
gem 'rspec-rails'
gem 'factory_girl_rails'
end
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 = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
end
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.
4
Answers
$alert-padding
variable is used before being defined. It may be caused by a wrong order of css files inapplication.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: https://github.com/twbs/bootstrap-sass#a-ruby-on-rails You need to renameapplication.css
toapplication.scss
and use@import
instead ofrequire
.With
SASS
you have to include your variables before they’re called.Dir globbing / Sprockets include files alphabetically:
This means if you’re using a
variables.sass
(or similar), you’ll want to either rename it, or include it explicitly:Even better (since you’re using
SASS
), use the@import
directive:I had a same issue
I just added this two lines in environment/production.rb
It works for me.
Just add these lines in your config/application.rb if you are using scss instead of css.