在 Rails 中自动从 SASS/SCSS 更新 CSS?

发布于 2024-09-05 08:02:42 字数 379 浏览 5 评论 0原文

也许我对 SASS/SCSS 在 Rails (2.3.8.) 中的工作方式感到困惑,但我的印象是,如果我包含

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

每当我更改 SCSS 文件然后再次点击页面(控制器)时的选项,SCSS会重新编译。

我似乎无法让它工作,并且似乎无法找到一个好的教程/示例。我尝试在Environment.rb 文件中设置上述属性,但它似乎没有做任何事情。我尝试使用 require 'sass' 将其放入自己的初始化程序中,但这似乎也不起作用。

我缺少什么?或者我只是被迫保持终端打开并运行 sass --watch 命令以便能够快速调试/更改我的样式?

谢谢

Maybe I'm confused on how SASS/SCSS works within Rails (2.3.8.) but I was under the impression that if I included the option

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

that whenever I changed my SCSS file and then hit the page (controller) again, the SCSS would recompile.

I can't seem to get this to work, and can't seem to find a good tutorial / example for it. I've tried setting the above property in the Environment.rb file, but it didn't seem to do anything. I tried putting it in its own initializer with require 'sass' but that doesn't seem to work either.

What am I missing? Or am i just forced to keep a terminal open with a sass --watch command running to be able to rapidly debug / change my styles?

thx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

迷你仙 2024-09-12 08:02:42

我正在使用 Rails 3.1,但遇到了同样的问题。在 sass-rails gem 中,文档说

: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.

这可以解释为什么你的 :always_update< /code> 选项不起作用。

对于我的问题,这很大程度上是因为我将development.rb中的config.action_controller.perform_caching设置为true(以修复旧gem中的一些其他错误)。所以为了修复它,我将其更改为:

# config/environments/development.rb
config.action_controller.perform_caching = false

I'm using rails 3.1, but had the same issue. In the sass-rails gem, the 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 :always_update option wasn't working.

For my problem, it was pretty much because I had config.action_controller.perform_caching in development.rb set to true (to fix some other bug in an old gem). So to fix it I changed it to:

# config/environments/development.rb
config.action_controller.perform_caching = false
初心未许 2024-09-12 08:02:42

确保在 Rails 项目中运行 compass init。它将设置以下内容:

  • config/compass.rb
  • config/initializers/compass.rb

Make sure you run compass init in your rails project. It will set up the following:

  • config/compass.rb
  • config/initializers/compass.rb
多彩岁月 2024-09-12 08:02:42

您应该重新加载控制器的普通视图,而不仅仅是直接加载样式表。

顺便说一句,正如文档所述 :always_update 会在每次控制器重新加载时更新 css 文件:

CSS 文件是否应该
每次控制器更新时
访问,而不是仅当
模板已修改。默认值
为假。只在其中有意义
Rack、Ruby on Rails 或 Merb。

You should reload a normal View of a Controller instead of just the stylesheet directly.

btw, as the documentation says :always_update updates the css files on every controller reload:

Whether the CSS files should be
updated every time a controller is
accessed, as opposed to only when the
template has been modified. Defaults
to false. Only has meaning within
Rack, Ruby on Rails, or Merb.

入画浅相思 2024-09-12 08:02:42

我遇到了问题,我的文件名以 .css.scss 结尾。使用 .scss 后它就可以工作了。

I had the problem, that I name my files ends with .css.scss. After just using .scss it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文