简体   繁体   English

服务器重启时Ruby on Rails 6 Bootstrap未定义变量错误

[英]Ruby on Rails 6 Bootstrap undefined variable error on server restart

I am having a problem in rails 6 where when i restart my server I get Error: Undefined variable.我在 rails 6 中遇到问题,当我重新启动服务器时,出现错误:未定义变量。 If I comment out any scss variables in my files, refresh the page, un-comment the variables and refresh again everything works fine and I am able to use variables in my CSS files again.如果我注释掉文件中的任何 scss 变量,请刷新页面,取消对变量的注释并再次刷新一切正常,我可以再次在我的 CSS 文件中使用变量。 Im not really sure why this is happening and any help anyone can offer would be really appreciated.我不太确定为什么会发生这种情况,任何人都可以提供任何帮助,我们将不胜感激。

Here is my application.scss file:这是我的 application.scss 文件:

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
 * vendor/assets/stylesheets directory can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
 * files in this directory. Styles in this file should be added after the last require_* statement.
 * It is generally better to create a new file per style scope.
 *
 *= require_self
 */

@import "custom_variables";
@import 'bootstrap/scss/bootstrap';
                                             
@import "@fortawesome/fontawesome-free/css/all.css";
@import 'layouts';
@import 'themes';
@import 'typography';
@import 'states';

and here are the files I am using variables in:以下是我在其中使用变量的文件:

.dropdown-menu {
    display: block;
    visibility: hidden;
    opacity: 0;
    transition: all .3s;
}

@media only screen and (min-width: map_get($grid-breakpoints,"lg")) {
    .dropdown:hover>.dropdown-menu {
        visibility: visible;
        opacity: 1;
    }
}

@media only screen and (max-width: map_get($grid-breakpoints,"lg")) {
    .dropdown-menu {
        display: none;
    }
}

.footer a:hover {
    text-decoration: none;
}

.bg-dark-red {
  background-color: $banner-color;
}

.navbar, .footer {
  background-color: $navbar-bg-color;
  
  a {
    color: $navbar-color;
  }

  a:hover {
    color: $navbar-hover-color;
  }

  .active {
    color: $navbar-active-color;
  }
}

.dropdown-menu {
  background-color: $navbar-bg-color;
  
  a {
    color: $navbar-color;
  }

  a:hover {
    color: $navbar-hover-color;
    background-color: inherit;
  }

  .dropdown-divider {
    border-top-color: $dropdown-border-color;
  }
}

section.map {
  background-color: $map-bg-color;
}

.btn-primary {
  @include button-variant($primary-btn-color, darken($primary-btn-color, 7.5%), darken($primary-btn-color, 10%), lighten($primary-btn-color,5%), lighten($primary-btn-color, 10%), darken($primary-btn-color,30%));
} 

Any suggestions on what I can do to stop this from occurring?关于我可以做些什么来阻止这种情况发生的任何建议?

EDIT: I forgot to include the file where I am importing the variables, here it is:编辑:我忘记包含导入变量的文件,这里是:

$white: #fff;
$black: #000;
$primary-color: #FF0103;
$complementary-color: complement($primary-color);

$navbar-color: rgba($white, .55);
$navbar-bg-color: #343A40;
$navbar-hover-color: rgba($white, .75);
$dropdown-border-color: rgba($black, .15);
$navbar-active-color: $white;

$banner-color: $primary-color;
$primary-btn-color: #198754;
$map-bg-color: #E1E1E1;

I was also facing the same exact issue.我也面临着同样的问题。 It was so frustrating.这太令人沮丧了。 First get rid of all the comments in the application.scss file especially the line that has *= require_self .首先删除 application.scss 文件中的所有注释,尤其是具有*= require_self Any file that uses bootstrap variables should have @import 'bootstrap/scss/bootstrap';任何使用引导变量的文件都应该有@import 'bootstrap/scss/bootstrap'; at the top.在顶部。 The following will NOT work:以下将不起作用:

application.scss:应用程序.scss:

@import 'bootstrap/scss/bootstrap';
@import 'custom.scss"

custom.css:自定义.css:

body {
    background-color: $gray-200;
}

Instead move the line @import 'bootstrap/scss/bootstrap';而是移动@import 'bootstrap/scss/bootstrap'; from application.scss to custome.scss, then it will work as shown below:从application.scss 到custome.scss,然后它将如下所示工作:

custom.scss:自定义.scss:

@import 'bootstrap/scss/bootstrap';
body {
    background-color: $gray-200;
}

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

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