我的 .scss 不在我的 ruby 应用中

My .scss aren't considered in my ruby app

我是 ruby 开发的新手,如果我的问题一开始就不太准确,请提前致歉。

我尝试应用 css 样式,但我使用的方式并不像我认为的那样有效。

index.html.erb 来自家庭控制器 app/views/home

<div class="box_home">
    ...
    ... 
</div>

home.scss app/assets/styelsheets

.box_home { margin-bottom: 20px; }

application.scss app/assets/styelsheets

@import "bootstrap-sprockets";
@import "bootstrap";
body { padding-top: 50px; }
.box_home { margin-bottom: 20px; }

没有发生那样的事情。但是如果我在 application.scss 中插入 css 属性 它就可以了。

这是正确的做法还是我应该在每个控制器的 scss 文件中分散样式?如果是,如何?

我试图找到文档或较早的问答,但我没有。

在此先感谢您的帮助。

您是否需要 application.css 中的此文件?

*= require home

如果您正在使用 SCSS 文件,您实际上应该在 application.scss

中使用 @import 而不是 require
@import "bootstrap-sprockets";
@import "bootstrap";
@import "home";
// ...

来自 rails 资产管道 documentation

If you want to use multiple Sass files, you should generally use the Sass @import rule instead of these Sprockets directives. When using Sprockets directives, Sass files exist within their own scope, making variables or mixins only available within the document they were defined in.