rails 3.2和对css文件的修改直到资产才反映:预编译

时间:2012-02-11 18:39:39

标签: ruby-on-rails ruby-on-rails-3

我正在创建一个新的rails 3.2项目,除了我在css文件上做的最后修改外,一切都正常。

如果app/assets/stylesheets/application.css更改了此文件的任何内容,在控制台上运行以下命令之前,我无法在浏览器上看到更改:

bundle exec rake assets:precompile RAILS_ENV=development

我的config/environment/development.rb文件。

Sample::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb

  # In the development environment your application's code is reloaded on
  # every request. This slows down response time but is perfect for development
  # since you don't have to restart the web server when you make code changes.
  config.cache_classes = false

  # Log error messages when you accidentally call methods on nil.
  config.whiny_nils = true

  # Show full error reports and disable caching
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send
  config.action_mailer.raise_delivery_errors = false

  # Print deprecation notices to the Rails logger
  config.active_support.deprecation = :log

  # Only use best-standards-support built into browsers
  config.action_dispatch.best_standards_support = :builtin

  # 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.5

  # Do not compress assets
  config.assets.compress = false

  # Expands the lines which load the assets
  config.assets.debug = true
end

任何帮助?

3 个答案:

答案 0 :(得分:16)

问题在于我编译了资产,因此rails正在为这些文件的已编译版本提供服务。

在这种情况下,您只需删除已生成的文件,例如application.cssapplication.css.gz,您就可以重新使用它了。

希望它有所帮助。

答案 1 :(得分:1)

运行捆绑exec rake assets:clean解决了这个问题。此外,如果您想手动删除这些文件,它们将出现在资产中应用程序的公共文件夹中。

答案 2 :(得分:1)

这是一个老话题,但我发现有时rake assets:clean在Rails 4.2.1中不会处理它。有时,您需要使用更强大的动词,例如clobber:rake assets:clobber