簡體   English   中英

服務器重啟時Ruby on Rails 6 Bootstrap未定義變量錯誤

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

我在 rails 6 中遇到問題,當我重新啟動服務器時,出現錯誤:未定義變量。 如果我注釋掉文件中的任何 scss 變量,請刷新頁面,取消對變量的注釋並再次刷新一切正常,我可以再次在我的 CSS 文件中使用變量。 我不太確定為什么會發生這種情況,任何人都可以提供任何幫助,我們將不勝感激。

這是我的 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';

以下是我在其中使用變量的文件:

.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%));
} 

關於我可以做些什么來阻止這種情況發生的任何建議?

編輯:我忘記包含導入變量的文件,這里是:

$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;

我也面臨着同樣的問題。 這太令人沮喪了。 首先刪除 application.scss 文件中的所有注釋,尤其是具有*= require_self 任何使用引導變量的文件都應該有@import 'bootstrap/scss/bootstrap'; 在頂部。 以下將不起作用:

應用程序.scss:

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

自定義.css:

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

而是移動@import 'bootstrap/scss/bootstrap'; 從application.scss 到custome.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