简体   繁体   English

Ruby on Rails资产管道似乎正在添加不存在的样式

[英]Ruby on Rails asset pipeline appears to be adding styles that don't exist

I'm completely stumped by this. 我对此深感困惑。 My SCSS file shows this: 我的SCSS文件显示如下:

.segmented-control {
  li .field_with_errors label {
      border-color: #db5757;
  }
}

But when I load the page and inspect the css, it shows this: 但是,当我加载页面并检查CSS时,它显示如下:

/* line 1382, /general.scss */
.segmented-control li .field_with_errors label,
.form-item-segmented-control li .field_with_errors label {
  border-color: #db5757;
}

The line number, 1382, points exactly to the first code snippet that I showed. 行号1382恰好指向我显示的第一个代码段。 Yet in the compiled version it includes an extra selector that includes .form-item-segmented-control . 但是在编译版本中,它包括一个额外的选择器,该选择器包括.form-item-segmented-control

I do use .form-item-segmented-control in other places in the CSS, but not here. 我确实在CSS的其他位置使用了.form-item-segmented-control ,但此处未使用。 And it is definitely not nested or anything like that. 而且它绝对不是嵌套的或类似的东西。

I'm utterly stumped. 我完全陷入了困境。 Any ideas of what Rails could possibly be doing? 关于Rails可能会做什么的任何想法? Or even ideas of how I could debug further? 甚至关于如何进一步调试的想法?

Okay, after some more debugging I believe I figured it out. 好吧,经过更多调试后,我相信我已经解决了。 It looks like it was due to an @extend that I had used earlier in the file. 看来这是由于我早先在文件中使用了@extend所致。 I hadn't realized all of the effects of @extend previously. 我以前没有意识到@extend所有作用。

It looks like if I do something like: 看起来好像我在做类似的事情:

.form-item-segmented-control {
    @extend .segmented-control;
}

ever in the file, it will then add the .form-item-segmented-control selector to all occurrences of .segmented-control . 永远不会在文件中,然后将.form-item-segmented-control选择器添加到所有出现的.segmented-control An important nuance to note, though, is that it will NOT do the same for occurrences of .segmented-control in other SCSS partials; 但是,需要注意的一个重要细微差别是,对于其他SCSS部分中的.segmented-control ,它不会做同样的事情。 the @extend only affects the file it is used in. @extend仅影响使用它的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM