I am trying to use bootstrap in rails using the gem 'bootstrap-sass' with the following setting in initializers
Below is the code in my application.css and common.css below that is a screenshot of my asset structure:
#app/assets/stylesheets/application.css.scss
*= require_self
*= require ./store/_common
*= require font-awesome
#app/assets/stylesheets/store/_common.css.scss
// import the CSS framework
@import "bootstrap-sprockets";
@import "bootstrap-custom";
@import "footer";
@import "header";
..
..
The problem is that, even though I've already imported the bootstrap files in my common.css still I have to manually import them in every file, in which I want to use the bootstrap variables or mixins. e.g. in _footer.css.scss
I am trying to use the variable $gray-lighter
or extend the .thumbnail
class and getting an error
Undefined variable: "$gray-lighter".
As soon as I add the line @import "bootstrap-variables-custom"; on top of this file, the error withers away.
I tried changing the application.css as follows, while removing the first two imports from common.css but it didn't work:
*= require_self
*= require _bootstrap-sprockets
*= require _bootstrap-custom
*= require store/_common
*= require font-awesome
UPDATE:- My current structure is as follows, with this structure I do not have to include bootstrap-custom in every file which is included in common.css but in every other file like taxons_show.css it is required. I tried moving this bootstrap-custom import to application.css, but it didn't work:
Rails.application.config.assets.precompile += %w( dashboard/* dashboard.css dashboard.js store/taxons*)
#app/assets/stylesheets/application.css.scss
*= require_self
*= require ./store/_common
*= require font-awesome
#app/assets/stylesheets/store/_common.css.scss
// import the CSS framework
@import "bootstrap-custom";
@import "footer";
@import "header";
.....
....
#app/assets/stylesheets/store/taxons_show.css.scss
@import "bootstrap-custom";
#product-listings {
padding: 30px;
display: flex;
flex-wrap: wrap;
.product_card {
margin-bottom: 50px;
border: none;
@extend .thumbnail;
h3 {
color: $gray;
margin-top: 10px;
font-size: 1.5em;
}
.price {
color: $gray;
font-size: 1.7em;
}
}
}