更改application.js时如何避免在Rails> = 3.1资产管道中进行预编译

在升级到rails 3.1(以及之后的3.2)后,我在资产管道中预编译了我的文件。现在(在开发模式下工作)我必须在每次更改后重新编译它们才能看到它们出现。 由于这需要大约一分钟,因此开发几乎是不可能的。

我在config/development.rb做了以下相关条目

 config.cache_classes = false # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false # Do not compress assets config.assets.compress = false config.assets.compile = true # Expands the lines which load the assets config.assets.debug = true # Raise exception on mass assignment protection for Active Record models config.active_record.mass_assignment_sanitizer = :strict # Log the query plan for queries taking more than this (works # with SQLite, MySQL, and PostgreSQL) config.active_record.auto_explain_threshold_in_seconds = 0.3 # configuration option config.assets.logger to control Sprockets logging config.assets.logger = nil 

怎么了? 我怎样才能看到我在application.js和其他人突然发生的变化?

一个人必须手动做

  $ bundle exec rake assets:clean 

这将删除[app]/public/assets/中的所有文件。 (注意其他文件,属于模型(如用户图片),它们也会被删除!)。

当文件不存在时,使用原始文件。 因此,预编译资产似乎不是开发模式所必需的。

感谢@shingara对这个问题的评论提示。

可能是一个因素,如果以下指令在config / application.rb中:

 config.assets.precompile += [ 'asset-file', ... ] 

这应该限制为“固定”资产文件,或者移动到config / environments / production.rb。

不确定是否会出现这种情况,但是在编辑资产文件后会产生类似的结果。 不预编译资产将使您无需在开发中的每次迭代中编译它们。