Encountering an undefined variable error with Ruby on Rails 6 Bootstrap after restarting the server

I'm facing an issue in rails 6 where upon server restart, I encounter an Error: Undefined variable. Oddly enough, if I comment out the SCSS variables in my files, refresh the page, then un-comment them and refresh again, everything works as expected and I can utilize variables in my CSS files once more. The root cause of this behavior eludes me, so any guidance or assistance would be greatly appreciated.

This is my application.scss file:

/*
 * 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 these are the files where I use variables:

.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 recommendations on how to prevent this issue from happening?

EDIT: I neglected to include the file where I import the variables, adding it here:

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

Answer №1

Dealing with the same issue was incredibly frustrating for me as well. To resolve it, the first step is to remove all comments from the application.scss file, especially the line containing *= require_self. Any file utilizing bootstrap variables needs to have

@import 'bootstrap/scss/bootstrap';
at the beginning. The following setup will not function as expected:

application.scss:

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

custom.css:

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

Instead, transfer the line

@import 'bootstrap/scss/bootstrap';
from application.scss to custom.scss. Then, everything should work correctly as demonstrated below:

custom.scss:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I make an image tag perfectly fit a CSS grid cell without using object-fit?

In this Vue component, the parent element displays 8 instances of these components in a 2x4 grid layout. The issue arises when the image within each component is larger than its container, causing it to not shrink to fit while maintaining the aspect ratio ...

Adjust the primary scrolling section of a webpage to halt once it reaches a specific distance from the bottom of the viewport

I am facing a situation where I need to ensure that when scrolling down, a fixed pink menu bar at the bottom of the page does not overlap with the main blue content. This can be achieved by treating the blue content as an iframe positioned 60px from the bo ...

changing pictures with jquery

Struggling with this code snippet: $('#clicked_package').css({"background-image" : "url(img/head_2.png)"}).fadeOut("slow"); $('#clicked_package').css({"background-image" : "url(img/head_2_normal.png)"}).fadeIn("slow"); No matter which ...

Click on the entire table to be redirected to the specified link

Currently, I am facing an issue with styling my tables as links. I have 3 tables and I want each table to be a clickable link. However, after implementing the links, I am unable round the corners of the tables. I envision the final look to be similar to t ...

Looking to replicate a Modal that I designed, but unsure which elements need altering in order to achieve this. I am hoping to create three duplicates of the Modal

This modal is functioning perfectly, and now I want to replicate the same modal three times on a single page. I require three distinct buttons on the same page to trigger these separate modals. At this point, I am unsure which attributes need modification ...

What's the trick to making a column that's 2/3 wide in a 34grid layout?

Is it possible to use the 34 Responsive Grid system to create a column that takes up two-thirds of the full width? Although the Grid System has equal columns settings, I'm curious how to combine or merge two columns together? <div class="containe ...

How is it that the magic table refuses to conform to CSS styling? This is truly sorcery!

My HTML table is as simple as it gets: <table class="dispdtab"> <tr> <td><b>Dealer: </b></td> <td>dealername</td> </tr> <t ...

Is it possible for Penthouse to retrieve critical CSS while using javascript?

I am currently utilizing the laravel-mix-criticalcss npm package to extract the critical CSS of my website. This package leverages Penthouse under the hood, and you can configure Penthouse settings in your webpack.mix.js within the critical options. The ...

"The PHP script was executed despite having a MIME type of "text/html", which is not an appropriate JavaScript MIME type" error

I'm encountering an issue while trying to add data to an Oracle database using PHP from a Bootstrap form. When attempting to run the HTML file in Mozilla Firefox, the following error is displayed: The script from “http://localhost/CustomerPartInAs ...

The appearance of unnecessary empty spaces at the conclusion of the page

.article-image1 { height: 256px; width: 256px; } .article-image1:before { content: ''; position: absolute; height: 100%; width: 100%; top: 0; left: 0; background-image: url(http://limootoys.com/wp-content/uploads/gentleman-e150 ...

Struggling to implement custom media queries in a bootstrap theme

I've customized the Twitter Bootstrap layout for my website, and everything is looking great except for the @media queries. Can anyone help me figure out what's going wrong? HTML: <section id="lessons" class="bg-black no-padding lesson-conte ...

Conceal a particular object from view by selecting it from the menu

I want to hide a specific element when the burger button is clicked. (See CaptureElementNoDisplay.PNG for the element to hide) When I click the burger button again to close the menu, I want the hidden item to be displayed once more. I've successfull ...

Effortlessly sleek horizontal navigation bar designed with Liquid CSS

I've been exploring online tutorials to create a responsive horizontal drop-down menu navigation bar using just CSS and HTML. The tutorial process has been smooth so far, but I'm aiming to make my navigation bar fluid so that it adjusts seamlessl ...

Is it possible to personalize a select button for both iOS and Android mobile platforms?

I've implemented a dropdown on my website for the desktop version and it works fine. However, I want to replace this dropdown with a select button on iPad and iPhone, as I prefer how it looks on those devices. Is it possible to style the select butto ...

Centered on the screen are the input field and corresponding label

I am in the process of creating a signup form, and I have encountered an issue. How can I make the input wider without using a fixed width like width: 420px? Additionally, I would like to center both the input field and the label. I envision something simi ...

Tips for employing 'live CSS' in Rails

As someone who is new to Ruby on Rails, I am currently facing a challenge. I want to extract data from specific fields in my database and utilize them for styling purposes. For instance, within my 'Student' database, there are height and width f ...

Styling for the DataTable disappears upon loading jQuery

my PHP file named "zero3data.php" <?php printf('<table cellpadding="0" cellspacing="0" border="0" class="display" id="example" width="100%">'); printf('<thead>'); printf('<tr>'); ...

Toggle visibility of div content when hovering over a link by leveraging the data attribute, with the div initially visible

I have a collection of links: <p><a href="#" class="floorplan initial" data-id="king"><strong>King</strong></a><br> 4 Bedrooms x 2.5 Bathrooms</p> <p><a href="#" class="floorplan" data-id="wood">< ...

Is it possible to align two buttons side by side on a webpage using only HTML and CSS?

Can you help me figure out how to align two buttons next to each other with some space between them using only css and html? If you take a look at my html code and css code, you'll see that the two buttons are not aligned properly. * { margin: 0 ...

Matching start and end of CSS selectors using regex

If I have elements with a title attribute like the examples below, how can I select the div with the title custom-marker-wqs-tailrace bbu-l2 using a CSS regex selector? <div title="custom-marker-awlr-tailrace bbu-l2"></div> <div ti ...