有时(不可预测)我的Rails应用程序通过摘要服务我的资产。有时,没有

时间:2015-04-27 12:14:52

标签: ruby-on-rails nginx asset-pipeline

查看我的主页的来源:

  <link data-turbolinks-track="true" href="/assets/application-ea3565aaa6bc4c481fc9425308d6bd54.css" media="all" rel="stylesheet" />
  <script data-turbolinks-track="true" src="/assets/application-2192d37159557835f39e5f3914e03276.js"></script>

然后我从“隐身”窗口刷新......

  <link data-turbolinks-track="true" href="/stylesheets/application.css" media="all" rel="stylesheet" />
  <script data-turbolinks-track="true" src="/javascripts/application.js"></script>

然后我再次刷新。它恢复原状。

你可以想象,这种行为令人非常沮丧。

我正在使用Unicorn + nginx。摘录自config/environments/production.rb

  config.cache_classes = true

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both thread web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.
  config.eager_load = true

  # Full error reports are disabled and caching is turned on.
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Disable Rails's static asset server (Apache or nginx will already do this).
  config.serve_static_assets = true

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = true

  # Generate digests for assets URLs.
  config.assets.digest = true

使用摘要生成资产的curl标头:

< HTTP/1.1 200 OK
* Server nginx/1.4.6 (Ubuntu) is not blacklisted
< Server: nginx/1.4.6 (Ubuntu)
< Date: Mon, 27 Apr 2015 12:22:32 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Status: 200 OK
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-UA-Compatible: chrome=1
< ETag: "b2c85c1389b561dadeb93132827e948d"
< Cache-Control: max-age=0, private, must-revalidate
< Set-Cookie: _Foobar_session=EVN3bklLdk9zVE93YllRVVRNY21BejdGRlJJTVUya1JycmlkYUJwSVFjV1lQcmp3em5LQlB1OUlWYk8zRlZlVS8rZTlLQkx4N0MrT1lCUWc4MkgvUTB5YklFUC9XRnJPZTZnTXM0OENPdmtiaWlpTUpOMlRJZUMvb2F4N0dLMEZVZjJDZ1hMdUFHT3k4VzdvMXk4NFJhcE03YysvTUdHUzgvbm5jY0g1UnozaXdtem1SdjYvU25MdFpiL1dqWlVnLS1WbWNHZ3JleHZaWERTbjllVFpFUHVnPT0%3D--1ac9ee1e8f941da47069271998f8cbdec9df68a0; path=/; HttpOnly
< X-Request-Id: 4ff86cd4-229c-4d8b-8f85-71c5f56af0d6
< X-Runtime: 0.016675
< 

没有摘要:

< HTTP/1.1 200 OK
* Server nginx/1.4.6 (Ubuntu) is not blacklisted
< Server: nginx/1.4.6 (Ubuntu)
< Date: Mon, 27 Apr 2015 12:22:30 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Status: 200 OK
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-UA-Compatible: chrome=1
< ETag: "141287c98bf53d0894adb5d754bcc2fd"
< Cache-Control: max-age=0, private, must-revalidate
< Set-Cookie: _Foobar_session=XzRrc3BwZHY5dXYyMFRBRFQzTVVTNlZNOEZBbFNQZHdjZ0pSditEenY1YjA1N0h2aW1LeFhJZGdRQVJUZFByaGpaQnYzZkNTallTT0J5TGRmM2Y0ZzVwdjdHT0xabC9YeHk4NzV5TVJFVFk0RmFiVERMRnhwVTIwdDFPTjFFdml0eE1VQ3pSd2lvVGh6czNhT2Q4blZ2cm05K0dNZnhtNnZVOUtSQWdqdnQrSXZGNXcrNlRkYm9VTktnVTRMVmJqLS1saVNldE8zRVdmU3JyK1VqZDdUazN3PT0%3D--276bde7cd6c87d6860a32fac6796fd0ac12bf90b; path=/; HttpOnly
< X-Request-Id: f967633d-2fe5-4705-a6b0-467fb8ce867f
< X-Runtime: 0.019299

1 个答案:

答案 0 :(得分:1)

当设置缓存的某个地方时会发生这种情况,因此:

  1. 重新检查环境,应将其设置为production
  2. cache
  3. 中查看标题上的app/views/layouts/application.html
  4. 从远程服务器上的旧缓存文件中清除目录your_app/public/assets
  5. 然后重新部署

    希望它有所帮助。