Heroku资产文件始终为空 [英] Heroku asset files always empty
问题描述
$ curl -i http://www.boxscoregeeks .com / assets / application-c712146df692b0fca6c21c0bf1dddcd5.css
HTTP / 1.1 200 OK
内容类型:text / css
日期:2013年9月1日星期日00:50:10 GMT
Last-Modified:Sun,01 Sep 2013 00:46:54 GMT
状态:200 OK
X-Sendfile:/app/public/assets/application-c712146df692b0fca6c21c0bf1dddcd5.css
Content-长度:0
连线:keep-alive
要验证,本地没问题: p>
$ curl -I http:// localhost:3001 / assets / application-c712146df692b0fca6c21c0bf1dddcd5.css
HTTP / 1.1 200 OK
Last-Modified:星期六,31八月2013 03:46:55 GMT
Content-Type:text / css
Con帐篷长度:106237
连接:保持活动
服务器:瘦1.5.1代号直线剃刀
我的清单:
config.serve_static_assets = true
in my production.rb file。
gem'rails_12factor',group :: production
heroku labs:enable user-env-compile --app = YOUR_APP
。在我运行之前,尽管执行了步骤1和2,资源:预编译将不会运行。它总是尝试初始化生产数据库。
几乎所有的Google搜索都告诉我需要做以上这些事情,但在这里我仍然有一个空的applicaiton.css文件。任何帮助都会很棒。
谢谢!
我自己对这个问题的回答。
有问题的应用程序是我从rails 3升级而来的。因此,我构建并部署了一个空的新rails 4应用程序)。通过区分 production.rb
文件,我注意到非工作应用程序中有这样一行:
#指定您的服务器用于发送文件的标头
#(如果前端服务器不支持,请注释掉)
config.action_dispatch。 x_sendfile_header =X-Sendfile#将'X-Accel-Redirect'用于nginx
在新的rails 4应用程序中被注释掉了。 Heroku文档建议这样做:
config.action_dispatch.x_sendfile_header = nil#For Heroku
当我改变这个时,一切都按预期工作。当应用程序在rails 3中运行在Cedar上时,这似乎并不重要。
First, I did a hell of a lot of googling to even get things working on Heroku, but it seems that regardless of whether I let heroku pre-compile my assets during slug compilation, or if I precompile them myself and submit them, either way, my Rails 4 app's application.css is always empty:
$ curl -i http://www.boxscoregeeks.com/assets/application-c712146df692b0fca6c21c0bf1dddcd5.css
HTTP/1.1 200 OK
Content-Type: text/css
Date: Sun, 01 Sep 2013 00:50:10 GMT
Last-Modified: Sun, 01 Sep 2013 00:46:54 GMT
Status: 200 OK
X-Sendfile: /app/public/assets/application-c712146df692b0fca6c21c0bf1dddcd5.css
Content-Length: 0
Connection: keep-alive
To verify, it's fine locally:
$ curl -I http://localhost:3001/assets/application-c712146df692b0fca6c21c0bf1dddcd5.css
HTTP/1.1 200 OK
Last-Modified: Sat, 31 Aug 2013 03:46:55 GMT
Content-Type: text/css
Content-Length: 106237
Connection: keep-alive
Server: thin 1.5.1 codename Straight Razor
My checklist:
- I have
config.serve_static_assets = true
in my production.rb file. - I have
gem 'rails_12factor', group: :production
in my Gemfile - I did this:
heroku labs:enable user-env-compile --app=YOUR_APP
. Before I ran that, assets:precompile would not run, despite steps 1 and 2. It would always try to initialize the production database.
Almost all of my googling tells me to do these things above, but here I am still with an empty applicaiton.css file. Any help would be great.
Thanks!
I found my own answer to this question.
The app in question is one that I upgraded from rails 3. So I built and deployed an empty new rails 4 app (and this worked). By diffing the production.rb
files, I noticed that the non-working app had a line like this in it:
# Specifies the header that your server uses for sending files
# (comment out if your front-end server doesn't support this)
config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx
This config line is commented out in the new rails 4 app. And the Heroku docs recommend this:
config.action_dispatch.x_sendfile_header = nil # For Heroku
When I changed this, everything worked as expected. This did not seem to matter when the app was running on Cedar in rails 3.
这篇关于Heroku资产文件始终为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!