Rails css 资产管道未引入其他样式表。
Rails css asset pipeline not pulling in other stylesheets.
所以我正在构建一个应用程序并且我添加了 bootstrap-sass
gem。这是我的 gem 文件的样子:
gem 'rails', '4.2.6'
gem 'bootstrap-sass'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'bcrypt', '~> 3.1.7'
group :development, :test do
gem 'byebug'
gem 'sqlite3', '1.3.11'
end
group :development do
gem 'web-console', '~> 2.0'
gem 'spring'
end
group :production do
gem 'pg'
end
我的路线文件夹:
Rails.application.routes.draw do
root 'landing_page#home'
get 'users/new'
end
我有两个样式表 application.scss
和 landing_page.scss
。
我只是想设计我的目标网页的样式。但是,我无法从我的 landing_page.scss
中加载任何样式。如果放在 application.scss
中,我只能加载这些样式。
这里是application.scss
@import "bootstrap-sprockets";
@import "bootstrap";
/*
* 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, vendor/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 styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/
@mixin box_sizing {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.debug_dump {
clear: both;
float: left;
width: 100%;
margin-top: 45px;
@include box_sizing;
}
body{
background-color: #525252;
}
有人知道我做错了什么吗?为什么 sass 或只是普通的 css 在被放置在 landing_page.scss
中时没有被应用?
您想要 @import
部分到 sass 文件。请参阅 http://sass-lang.com/guide 了解分音的工作原理。
在您的情况下,您应该将 landing_page.scss
重命名为 _landing_page.scss
并在 application.scss
文件中执行 @import landing_page
。
所以我正在构建一个应用程序并且我添加了 bootstrap-sass
gem。这是我的 gem 文件的样子:
gem 'rails', '4.2.6'
gem 'bootstrap-sass'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'bcrypt', '~> 3.1.7'
group :development, :test do
gem 'byebug'
gem 'sqlite3', '1.3.11'
end
group :development do
gem 'web-console', '~> 2.0'
gem 'spring'
end
group :production do
gem 'pg'
end
我的路线文件夹:
Rails.application.routes.draw do
root 'landing_page#home'
get 'users/new'
end
我有两个样式表 application.scss
和 landing_page.scss
。
我只是想设计我的目标网页的样式。但是,我无法从我的 landing_page.scss
中加载任何样式。如果放在 application.scss
中,我只能加载这些样式。
这里是application.scss
@import "bootstrap-sprockets";
@import "bootstrap";
/*
* 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, vendor/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 styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/
@mixin box_sizing {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.debug_dump {
clear: both;
float: left;
width: 100%;
margin-top: 45px;
@include box_sizing;
}
body{
background-color: #525252;
}
有人知道我做错了什么吗?为什么 sass 或只是普通的 css 在被放置在 landing_page.scss
中时没有被应用?
您想要 @import
部分到 sass 文件。请参阅 http://sass-lang.com/guide 了解分音的工作原理。
在您的情况下,您应该将 landing_page.scss
重命名为 _landing_page.scss
并在 application.scss
文件中执行 @import landing_page
。