在“app/assets/stylesheet/application.css.scss”中我有以下代码:
/*
*= require_self
*= require_tree .
*/
然后我有“styles.css.scss”,其中包含我的应用程序的所有代码。
我的本地主机上的预编译 Assets 存在问题,应用程序从两个文件(“styles.css.scss”和“application.css.scss”)加载 CSS 规则。
当我检查具有不正确 CSS 规则的元素时,我看到 CSS 规则是从“styles.css.scss”和“application.css.scss”加载的。但是,“application.css.scss”是空的,那么这个文件怎么可能有CSS规则呢?
我也试过删除目录“public/assets”,但没有用。
我该如何解决这个问题?我已经为此工作了几个小时,但没有任何进展。
最佳答案
默认情况下,在开发模式下,config/environments/development.rb
中有以下内容:
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
"In development mode, assets are served as separate files in the order they are specified in the manifest file." (Source: http://guides.rubyonrails.org/asset_pipeline.html).
如果您将 config.assets.debug
设置为 false
那么所有样式(在本例中)将被组合并放入 application.css
。但是当 config.assets.debug
为 true
时,你的 application.css
将是空的,除非你有一些 css
那里规定的规则。
希望我没有误解你的问题:)
关于css - 为什么我的 Assets 加载不正确的 CSS 样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17372237/