尽管有变化,Rails仍使用缓存的application.css

我有一个使用SASS的Rails 3.1应用程序。 application.css.scss文件如下所示:

 @import 'reset.css'; @import '960.css'; @import 'pages/master.css.scss'; 

我有一个监视器脚本,只要更改了一个@imported文件,它就会触及application.css.scss

有一段时间,这个设置工作正常。 自上周以来(我不知道为什么),Rails已经为网页提取了一个缓存版本的application.css ,尽管我尝试重新启动应用程序,重新触摸application.css.scss等等。 ve还删除了.sass-cache无效。

有任何想法吗?

我遇到过同样的问题。 我停止了服务器,执行了rm -fr tmp/cache ,我的css文件终于重建了。

在运行rake assets:precompile之后我遇到了类似的问题rake assets:precompile在开发中rake assets:precompile 。 也许Rails正在为public/assets提供预编译public/assets ? 尝试清理它。

您不需要在开发中触摸aplication.css.scss,只要其中一个@included文件发生更改,rails就应该为新内容提供服务。

另外,请确保在config/environments/development.rb包含以下内容

 # Do not compress assets config.assets.compress = false # Expands the lines which load the assets config.assets.debug = true 

首先,通常的缓存清除健全性检查可能会有所帮助。 清除浏览器缓存。 清除服务器文件缓存(如果您在开发/测试中或能够负担生产)和sass-cache:

 rake tmp:cache:clear rm -fr tmp/sass-cache #or 'compass clean' if using compass 

如果这没有帮助,也许Rails在其他地方编译了另一个 application.css(没有被缓存清除删除)?

例如,我运行compass watch app/assets/stylesheets/application.css.scss用于调试目的,它创建了一个public / assets / application.css文件,由于它在public /中的位置,它阻止了任何新的application.css .scss样式表从Rails注意到变化。 删除后,应用程序再次从.scss样式表中删除。 这只是意外覆盖文件创建的一个示例。 尝试在整个应用程序目录中运行查找以查找任何生成的application.css文件,在清除缓存后执行此操作以避免在结果中显示这些文件。

(仅供参考,为了避免我的具体问题,我现在用–css-dir指向缓存来运行指南针监视以防止我的问题

 $ compass watch app/assets/stylesheets/application.css.scss --css-dir tmp/cache/ 

要消除资产管道缓存,强制rm -rf tmp / *就足够了。 这肯定解决了我的经验中一些令人费解的CSS和JavaScript故障。 作为一种预防措施,在升级gem或更改资产管道配置后清除缓存也是一个好主意,尽管这可能只是迷信。

最后,如果您正在尝试rake资产:在您的开发环境中进行预编译(稍后将在后面的文章中详细介绍),您还需要rm -rf public / assets / *来清理它。

http://blog.55minutes.com/2012/02/untangling-the-rails-asset-pipeline-part-1-caches-and-compass/

随机我遇到了与使用twitter bootstrap和application.css.scss相关的缓存问题。 基本上我将application.css.scss更改为普通的application.css并修复了我的问题。 也许这可以帮到你? 如果你还没有想出来的话。

我遇到了这个问题,但我实际上是把css放到application.css中,而不是放在它包含的文件中。 我清除了application.css以简单地包含我的所有CSS。 所以,我的application.css现在看起来像这样:

 /* * 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 top of the * compiled file, but it's generally better to create a new file per style scope. * *= require_self *= require 'bootstrap.min' *= require 'global' */ 

每当我更改其中一个包含的文件(例如global.css)时,我的更改都会反映出来