我已经有一段时间没有在Rails中进行开发了,我在刚创建的Rails应用程序中遇到了无法使任何scss
样式表起作用的问题。
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
,但它什么也没做。有人能解释一下它究竟是做什么的吗?
我尝试在application.scss
中添加* = require main
和* = require main.scss
。 我甚至将这两个文件的扩展名更改为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
*/
但是,仍然没有任何作用