【发布时间】:2013-09-04 10:37:48
【问题描述】:
首先,我做了很多谷歌搜索,甚至在 Heroku 上运行,但似乎无论我是让 heroku 在 slug 编译期间预编译我的资产,还是我自己预编译并提交它们,无论哪种方式,我的 Rails 4 应用程序的 application.css 始终为空:
$ 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
验证一下,本地没问题:
$ 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
我的清单:
- 我的 production.rb 文件中有
config.serve_static_assets = true。 - 我的 Gemfile 中有
gem 'rails_12factor', group: :production - 我这样做了:
heroku labs:enable user-env-compile --app=YOUR_APP。在我运行之前,assets:precompile 不会运行,尽管执行了第 1 步和第 2 步。它总是会尝试初始化生产数据库。
几乎我所有的谷歌搜索都告诉我要在上面做这些事情,但在这里我仍然有一个空的 applicaiton.css 文件。任何帮助都会很棒。
谢谢!
【问题讨论】:
-
同样在
production.rb中确保启用config.assets.precompile += %w( search.js )。不要使用config.assets.precompile = ['*.js', '*.css'],因为其他线程可能会建议。 -
完成后,还要确保运行
RAILS_ENV=production rake assets:precompile。然后提交并推送。