【问题标题】:Rails production isn't updating static assets on server restartRails 生产不会在服务器重启时更新静态资产
【发布时间】:2014-08-06 00:31:26
【问题描述】:

我在实际使用它之前在本地生产环境中运行我的代码。我在生产时注意到我的 javascript 中有一个错误,修复它,然后返回。该错误仍然存​​在。但是,我在 dev 中尝试过,并且该错误已完美修复!我重新启动了服务器,重新启动了我的计算机,并尝试了另一个 SO 问题中列出的解决方案来触摸 /tmp/restart.txt,但似乎没有任何东西可以让 Rails 重新加载资产。

我可以判断这不是浏览器问题,因为修复错误后,我将网页加载到之前没有看到生产环境的浏览器中,它表现出相同的行为。

这是我的生产配置:

Rails.application.configure do
  config.cache_classes = true
  config.eager_load = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.serve_static_assets = true 
  config.assets.js_compressor = :uglifier
  config.assets.compile = false.
  config.assets.digest = true
  config.assets.version = '1.0'
  config.log_level = :info
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  config.log_formatter = ::Logger::Formatter.new
end

如何让 rails 重新加载静态资源?

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    要重新生成您运行此命令的资产

    bundle exec rake assets:precompile RAILS_ENV=production
    

    我建议在 production.rb 中将此设置为 false,以便 apache/nginx 为资产提供服务。

    config.serve_static_assets = false
    

    【讨论】:

    • 谢谢!那行得通。我在 Windows 上运行,由于某种原因,当该命令设置为 false 时,根本不提供资产。不过,我最终计划将其移至 linux,因此我会牢记这一点。
    【解决方案2】:

    尝试运行:

    rake assets:clean
    

    资产可能在某一时刻被预编译,现在服务器将始终使用这些预编译资产(如果存在)。您也可以手动删除 /app-root/public/assets 文件夹以获得相同的效果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-10
      • 1970-01-01
      • 1970-01-01
      • 2013-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多