在 Rails 中自动从 SASS/SCSS 更新 CSS?
也许我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我正在使用 Rails 3.1,但遇到了同样的问题。在 sass-rails gem 中,文档说
这可以解释为什么你的
:always_update< /code> 选项不起作用。
对于我的问题,这很大程度上是因为我将development.rb中的
config.action_controller.perform_caching
设置为true(以修复旧gem中的一些其他错误)。所以为了修复它,我将其更改为:I'm using rails 3.1, but had the same issue. In the sass-rails gem, the docs say
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:确保在 Rails 项目中运行
compass init
。它将设置以下内容:Make sure you run
compass init
in your rails project. It will set up the following:您应该重新加载控制器的普通视图,而不仅仅是直接加载样式表。
顺便说一句,正如文档所述
:always_update
会在每次控制器重新加载时更新 css 文件: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:我遇到了问题,我的文件名以 .css.scss 结尾。使用 .scss 后它就可以工作了。
I had the problem, that I name my files ends with .css.scss. After just using .scss it works.