我预编译了我的资源并使用以下函数来渲染html:
= stylesheet_link_tag "frontend/application", media: "all", "data-turbolinks-track" => true
= javascript_include_tag "frontend/application", "data-turbolinks-track" => true
有时这些方法生成正确的html:
<link data-turbolinks-track="true" href="/assets/frontend/application-64cf06dd4d2386f145e00844fed60d28.css" media="all" rel="stylesheet" />
<script data-turbolinks-track="true" src="/assets/frontend/application-447281961c979f73e944369c4b832fd8.js"></script>
但是在生产轨道上,有时(50%!)会像这样生成资产html
<link data-turbolinks-track="true" href="/stylesheets/frontend/application.css" media="all" rel="stylesheet" />
<script data-turbolinks-track="true" src="/javascripts/frontend/application.js"></script>
我在生产中使用heroku。知道什么可能是错的或者我该如何解决这个问题?
以下是我的制作设置。
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = true
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Generate digests for assets URLs.
config.assets.digest = true
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '2'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
以下是此问题的预览:view-source:http://v5.megabon.com/en
答案 0 :(得分:0)
让它在Heroku上运行的唯一方法是将compile设置为false
config.assets.compile = false
并删除公用文件夹中的每个预编译文件。这迫使Heroku在每次git推送时重新编译资产。