Automatically update CSS from SASS / SCSS in Rails?

I might be confused about how SASS / SCSS works in Rails (2.3.8.), But I got the impression that if I turned on the option

Sass::Plugin.options[:always_update] = true 

so that whenever I change my SCSS file and then delete the page (controller) again, SCSS is recompiled.

I can't seem to get this to work, and I can't find a good tutorial / example for it. I tried to set the specified property in the Environment.rb file, but it did nothing. I tried putting it in my own initializer with the requirement of "sass", but this does not work either.

What am I missing? Or am I just forced to keep the terminal open with the sass -watch command, which allows me to quickly debug / change my styles?

THX

+4
source share
4 answers

I am using rails 3.1 but had the same problem. In sass-rails gem, docs say

 :always_update - This option is not supported. Sprockets uses a controller to access stylesheets in development mode instead of a full scan for changed files. 

which could explain why your parameter :always_update did not work.

For my problem, this was largely because I had config.action_controller.perform_caching in development.rb set to true (to fix any other error in the old gem). Therefore, to fix this, I changed it to:

 # config/environments/development.rb config.action_controller.perform_caching = false 
+2
source

Make sure you run compass init in the rails project. He will install the following:

  • config /compass.rb
  • config / Initializers / compass.rb
0
source

You must reload the normal view of the controller, not just the stylesheet directly.

btw, as the documentation says that :always_update updates css files every time the controller restarts:

Should CSS files be updated every time the controller access, as opposed to the template has been changed. Defaults to false. It only makes sense inside Rack, Ruby on Rails, or Merb.

0
source

I had a problem that I call my files ends .css.scss. After using .scss it works.

0
source

Source: https://habr.com/ru/post/1312722/


All Articles