Eric Norcross
Eric Norcross

Reputation: 4306

Rails 4 not updating css in dev when changes are made

I've been struggling with this for a while, but basically every time I make a change to my css files listed below (layout.scss for instance), I have to stop the server and run rake assets:clobber then restart the server before I can see the changes.

Needless to say, this is extremely tedious. Below is my config; please let me know if there is anything else you'd like me to post.

Gemfile

source 'https://rubygems.org'
ruby '2.2.3'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
  gem 'rails', '4.2.5'

# DB Tools
  gem 'pg'
  gem 'money-rails'
  gem 'pluck_to_hash'

# View Development Tools
  gem 'sassc-rails'
  gem 'haml-rails'
  gem 'friendly_id', '~> 5.1.0'

# View Display Tools
  gem 'jquery-rails'
  gem 'font-awesome-rails'

# Form Tools
  gem "cocoon"
  gem 'amoeba'

# Angular Tools
  gem 'angularjs-rails', '~> 1.4.7'
  gem 'angular-rails-templates'
  gem 'angular_rails_csrf'

# API Tools
  gem 'active_model_serializers', '~> 0.10.0.rc2'
  gem 'easy_diff'

# Authentication / Authorization
  gem 'devise'

# Use Uglifier as compressor for JavaScript assets
  gem 'uglifier', '>= 1.3.0'
  gem 'sdoc', '~> 0.4.0', group: :doc

# Hosting, Serving & Deployment
  gem 'puma'
  gem 'foreman'

# Env specific
group :development do
  gem 'awesome_print', :require => 'ap'
  gem "better_errors"
  gem "binding_of_caller"
  gem 'annotate', '~> 2.6.6'
  gem 'seed_dump'
end

group :development, :test do
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

development.rb

Rails.application.configure do
  config.cache_classes = false
  config.eager_load = false

  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  config.action_mailer.raise_delivery_errors = true

  config.active_support.deprecation = :log

  config.active_record.migration_error = :page_load

  config.assets.debug = true
  config.assets.prefix = "/dev-assets"
  config.assets.digest = false
  config.serve_static_files = false

  config.assets.raise_runtime_errors = true

  config.sass.inline_source_maps = true

  config.action_mailer.default_url_options = { host: 'localhost', port: 8080 }

  config.action_mailer.delivery_method = :smtp

  config.action_mailer.smtp_settings = {
    address:              "smtp.gmail.com",
    port:                 587,
    domain:               ENV["GMAIL_DOMAIN"],
    user_name:            ENV["GMAIL_USERNAME"],
    password:             ENV["GMAIL_PASSWORD"],
    authentication:       "plain",
    enable_starttls_auto: true
  }

end

application.css

/*
 *= require_self
 *= require application-loader
*/

application-loader.scss

// common/
@import 'common/flexbox.scss';
@import 'common/baseline.scss';
@import 'common/fonts.scss';
@import 'common/mixins.scss';

@import 'common/common.scss';
@import 'common/forms.scss';
@import 'common/layout.scss';
@import 'common/pages.scss';
@import 'common/svg.scss';

@import 'authenticated/modules/stats.scss';

// authenticated/
@import 'application/application-layout.scss';
@import 'application/application-forms.scss';

Upvotes: 1

Views: 1786

Answers (2)

Eric Norcross
Eric Norcross

Reputation: 4306

After chasing down an idea brought up by @gates in the comments of my original answer, I came across this blog post

Basically, since sprockets wasn't doing the loading, it seems that it wasn't recompiling changes to individual files (though I don't know why an overall recompile wasn't updating), so on the instruction of the blog, I now have sprockets loading all the files and I import mixins as necessary. Something like this:

application.css

/*
 *= require_tree ./common
 *= require_tree ./authenticated
 *= require font-awesome
 *= require_self
*/

authenticated/authenticated-layout.scss

@import '../flexbox.scss';
@import '../mixins.scss';

body {
  // etc...
}

I can now make a change to any of my scss files and reload the page without having to clobber the assets and/or restart the server!

Upvotes: 3

Krishna Teja Karnam
Krishna Teja Karnam

Reputation: 133

Do you think we need to add the file in 'initialisers/assets.rb'? This worked for me once.

Upvotes: 0

Related Questions