Ruby on Rails 教程自定义 CSS 未显示在应用程序中

2024-03-24

我正在运行 Michael Hartl 的 Ruby on Rails 教程,我的 boostrap sass 正在工作,但是我无法显示任何自定义修改。

在第 5.5 章中,我们添加了 bootstrap sass gem。这是我的 Gem 文件:

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.6'
gem 'sass', '~> 3.5', '>= 3.5.5'
gem 'autoprefixer-rails', '~> 7.2', '>= 7.2.5'
gem 'bootstrap-sass', '3.3.7'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'

捆绑安装后,系统指示我在下面创建一个自定义 css 文件

app/assets/stylesheets/custom.scss

在这里我们必须输入以下内容来导入引导程序:

@import "bootstrap-sprockets";
@import "bootstrap";

还有我们编写的一些自定义 CSS,因此 custom.scss 文件如下所示:

@import "bootstrap-sprockets";
@import "bootstrap";



body {
  padding-top: 60px;
}

section {
  overflow: auto;
}

textarea {
  resize: vertical;
}

.center {
  text-align: center;
}

.center h1 {
  margin-bottom: 10px;
}

/* typography */

h1, h2, h3, h4, h5, h6 {
  line-height: 1;
}

h1 {
  font-size: 3em;
  letter-spacing: -2px;
  margin-bottom: 30px;
  text-align: center;
}

h2 {
  font-size: 1.2em;
  letter-spacing: -1px;
  margin-bottom: 30px;
  text-align: center;
  font-weight: normal;
  color: #777;
}

p {
  font-size: 1.1em;
  line-height: 1.7em;
}

/* header */

#logo {
  float: left;
  margin-right: 10px;
  font-size: 1.7em;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: -1px;
  padding-top: 9px;
  font-weight: bold;
}

#logo:hover {
  color: #fff;
  text-decoration: none;
}

我重新启动服务器并查看我的应用程序,引导程序加载正常,但自定义 CSS 更改却无处可寻!

如果我查看源代码,所有 css 文件都会被编译

<link rel="stylesheet" media="all" href="/assets/custom.self-871a674bf18d1e8205b6a321a40cf6fdedb44cd5879414e213f9011fba10d9b0.css?body=1" data-turbolinks-track="reload" />
<link rel="stylesheet" media="all" href="/assets/static_pages.self-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css?body=1" data-turbolinks-track="reload" />
<link rel="stylesheet" media="all" href="/assets/application.self-af04b226fd7202dfc532ce7aedb95a0128277937e90d3b3a3d35e1cce9e16886.css?body=1" data-turbolinks-track="reload" />

当我打开 custom.cscc 文件时,我看到从 boostrap-sass gem 导入的完整引导源代码,但我的自定义修改无处可寻。我如何确保它们与引导程序一起编译?

玩弄我意识到我真的无法做出任何修改..一切似乎都已修复。

我已尝试多次重新启动服务器,刷新并尝试不同的浏览器(以确保有干净的缓存)。

Edit:

我的 application.css (教程从未指示更改为 .css.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,
 * vendor/assets/stylesheets, or vendor/assets/stylesheets of plugins, if any,
 * 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
 */

我会将 application.css 重命名为 application.scss,然后删除

 *= require_tree .
 *= require_self

我的 application.scss 看起来像这样。因此,每当我创建新的样式表时,我只需进入 application.scss 并导入它,以便 Rails 可以看到它。

/*
 * 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.
 *
 */

@import "bootstrap";
@import "font-awesome-sprockets";
@import "font-awesome";

/* add custom stylesheets here*/
@import "custom";
@import "sessions";
@import "users";
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Ruby on Rails 教程自定义 CSS 未显示在应用程序中 的相关文章

随机推荐

  • Ruby 相当于 grep -v

    这就是我一直在做的事情 my array reject elem elem regex each 我觉得这有点笨拙 但我还没有找到任何内置的东西可以让我将其更改为my array grepv regex 有这样的功能吗 Ruby 2 3 实
  • 如何使用DATA_PUMP导出到S3存储桶?

    我们有 RDS Oracle 实例 我需要将特定架构导出到转储文件中 导出工作并将转储文件复制到 DATA PUMP DIR 问题是 RDS 没有文件目录访问权限 我需要在 S3 上导出 DMP 文件或复制到另一个 EC2 实例 文章 LI
  • 轻松的十六进制/浮点转换

    我正在 c 和 python 程序之间进行一些输入 输出 仅浮点值 python 有一个很好的功能 可以将浮点值转换为十六进制数字并返回 如您在此链接中看到的 http docs python org library stdtypes ht
  • annotationProcessor gradle 4.7+ 配置不运行 lombok

    我在使用 gradle 4 7 项目时收到以下消息 The following annotation processors were detected on the compile classpath lombok launch Annot
  • IHTTPHandler 的无缓冲输出

    我想从一个流式传输数据IHttpHandler班级 我从数据库加载大量行 序列化并压缩它们 然后通过网络发送它们 另一方面 我希望我的客户端能够在服务器完成所有对象的序列化之前解压缩和反序列化数据 我在用着context Response
  • Angular 2 路由引发 404 错误

    HTML5 推送状态意味着刷新 URL 或在浏览器中输入直接 URL 当我使用以下命令运行我的 Angular 应用程序时效果非常好 npm start 来自 VS 2015 命令提示符的命令 但是 当我在 IIS 上部署相同的应用程序并更
  • Silverlight-DataGrid 控件-选择更改事件干扰排序

    我目前正在使用 Silverlight Beta 2 Datagrid 控件 在连接 SelectionChanged 事件之前 网格将通过单击标题完美排序 现在 当单击网格时 当我单击标题进行排序时 它将触发 SelectionChang
  • 从 panda 数据框中删除方括号

    我有一个数据框 我需要从中删除方括号才能输入到循环中 我尝试过使用 str strip 和 str commands 但是我收到错误消息 说我必须传递带有布尔值的数据帧 我的数据框中的值似乎是列表 m2 pd read csv newm2
  • Xamarin 中绑定 Jar 库时出现问题

    在绑定我的 jar 文件时 我不断在多个类中收到此错误 Error CS0534 path does not implement inherited abstract memberAndroid OS AsyncTask DoInBackg
  • SQL Server 数据库的大小有限制吗?

    我将用 C 开发一个系统 其中必须扫描和存储文档 我预计 dB 的大小将达到 3 4 TB 我的问题是可以将它们存储在数据库中还是数据库有限制 或者我是否必须将它们存储在文件夹中 提前致谢 是的 有一个限制 这取决于您使用的 SQL Ser
  • 与 CGAL 的链接错误

    我在 Mac OS X 10 8 4 上安装了 CGAL 我已成功地将 CGAL 的各个方面合并到以前的 C 程序中来计算 3D 点云的凸包 然而 现在我试图包含 CGAL 的其他部分来计算表面网格 将它们转换为多面体 等等 当我这样做时
  • 网格三角剖分和简化 C++ 库 [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我正在寻找一个 C 库来三角测量和简化 3D 网格 我的 3D 网格可能很大 大约 300 万个顶点
  • 将 Babel 添加到 HTML

    我是 ReactJS 新手 在将 babel 导入 html 时遇到问题 目前该项目托管在code pen上链接到代码笔 https codepen io davedaw pen JJgvGK editors 1010 我正在尝试在本地主机
  • 如何在 Rust 中返回字符串向量

    如何通过分割中间有空格的字符串来返回字符串向量 fn line to words line str gt Vec
  • 如何在Raku中逐行读取gz文件

    我正在尝试在 Raku 中逐行读取一个巨大的 gz 文件 我正在尝试做这样的事情 my file huge file gz for file IO lines gt line say line 但这给出了我的 UTF 8 格式错误的错误 我
  • OpenCV::dnn::readNet 抛出异常

    我正在关注本教程 https learnopencv com object detection using yolov5 and opencv dnn in c and python 加载yolov5 onnx使用 OpenCV DNN 模
  • CPU如何对指令重新排序

    我最近读到了有关 CPU 指令重新排序以提高效率的内容 但我无法理解CPU如何重新排序其指令 我的意思是编译时重新排序是可以想象的 因为编译器可以预见即将到来的代码 但是对于一个接一个地读取指令的CPU 它如何看到即将到来的指令并对它们重新
  • 计算实验室信息系统 (LIS) 帧的校验和

    我正在开发一个仪器驱动程序实验室信息系统 https www limswiki org index php Laboratory information system 我想知道如何计算帧的校验和 校验和算法说明 用字符 0 9 和 A F
  • 我应该在每个视图中都有一个 NSFetchedResultsController 吗?

    我在我的第一个 iPhone 应用程序中使用 Core Data 并尝试理解 NSFetchedResultsController 它在我的根视图中效果很好 我是否需要在每个视图控制器中实例化一个实例 如果是这样 是否有一个模板可以使这像在
  • Ruby on Rails 教程自定义 CSS 未显示在应用程序中

    我正在运行 Michael Hartl 的 Ruby on Rails 教程 我的 boostrap sass 正在工作 但是我无法显示任何自定义修改 在第 5 5 章中 我们添加了 bootstrap sass gem 这是我的 Gem