我的rails样式表没有加载/工作

Phi*_*p C 9 css ruby-on-rails ruby-on-rails-4

自从我在Rails中开发以来已经有一段时间了,我无法使用任何scss样式表来处理我新创建的rails应用程序.

layouts/application.html.erb默认<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>位于顶部.

出于测试目的,我创建了一个main.scss文件assets/stylesheets/,如下所示:

* {
border: 1px solid black;
}
Run Code Online (Sandbox Code Playgroud)

我认为该application.scss文件应该抓住它的文件夹和子文件夹中的所有样式表,但事实并非如此.(奇怪的是,.js文件加载得很好.)

我尝试过,RAILS_ENV=production rake assets:precompile但没有做任何事情.有人可以解释它甚至做了什么吗?

我已经尝试添加*= require main*= require main.scssapplication.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
 */
Run Code Online (Sandbox Code Playgroud)

但是,没有任何作用

小智 6

 /*
 *= require_tree .
 *= require_self
 */
Run Code Online (Sandbox Code Playgroud)

将上述内容添加到您的 application.scss 或 application.css.scss 文件中


Phi*_*p C 3

看起来我能让它工作的唯一方法是添加@import main;application.scss. 看起来样式最终会在每个页面上使用(这是 Rails 中的默认样式吗?)。

这不是我理想的解决方案,但这是我能够做的唯一一件事,可以通过所需的方法让任何样式发挥作用。