【发布时间】:2023-03-28 16:00:02
【问题描述】:
自从我在 Rails 中开发以来已经有一段时间了,我无法让任何 scss 样式表在我新创建的 Rails 应用程序上工作。
layouts/application.html.erb 在顶部有默认的<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>。
出于测试目的,我在assets/stylesheets/ 中创建了一个main.scss 文件,如下所示:
* {
border: 1px solid black;
}
我认为application.scss 文件应该获取其文件夹和子文件夹中的所有样式表,但事实并非如此。 (奇怪的是,.js 文件加载得很好。)
我试过RAILS_ENV=production rake assets:precompile,但它什么也没做。有人能解释一下它的作用吗?
我尝试将*= require main 和*= require main.scss 添加到application.scss。我什至将两个文件的文件 ext 更改为 css。我得到任何 css 渲染的唯一方法是直接将代码添加到 application.scss,我不想这样做。
请帮帮我。
编辑 1
我将添加更多信息,因为我得到的是通用答案。我提到它是一个新的 Rails 应用程序,所以基本的东西已经预先生成。这就是我的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, 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 main
*= require_self
*/
仍然没有任何效果
【问题讨论】:
标签: css ruby-on-rails ruby-on-rails-4