尝试了几个修复:Heroku/Rails 4资产预编译错误

nic*_*tme 7 heroku asset-pipeline ruby-on-rails-4

看起来这是一个常见的问题,所以让我首先说我已经做了很多研究.

这个帖子之后,我跑了

heroku labs:enable user-env-compile -a myapp

然后我确保资产通过运行在本地预编译

RAILS_ENV=production bundle exec rake assets:precompile

他们是这样.

我也遵循这个提示,设置

config.assets.initialize_on_precompile = false

在我的config/production.rb和config/application.rb中.

此外,在这个问题之后,我确保安装了heroku gem:

gem 'rails_log_stdout',           github: 'heroku/rails_log_stdout'
gem 'rails3_serve_static_assets', github: 'heroku/rails3_serve_static_assets'
Run Code Online (Sandbox Code Playgroud)

然后我bin通过遵循这篇heroku文章确保我在我的道路上.

然后我确保我遵循heroku上的"Rails 4.xx入门" 文章.

我也跟着另一个回答这个问题,放在下面的application.rbproduction.rb

config.serve_static_assets = true
Run Code Online (Sandbox Code Playgroud)

这是运行时遇到的错误git push heroku master:

   Preparing app for Rails asset pipeline
   Running: rake assets:precompile
   rake aborted!
   could not connect to server: Connection refused
   Is the server running on host "127.0.0.1" and accepting
   TCP/IP connections on port 5432?
Run Code Online (Sandbox Code Playgroud)

似乎config.assets.initialize_on_precompile = false应该工作,因为它似乎试图在预补偿期间加载生产数据库.

我做了所有这些改变,并且他们已经被推进了git.现在我该怎么办?

nic*_*tme 3

嗯,对此感到抱歉。我想我没有推动的效果RAILS_ENV=production bundle exec rake assets:precompile。希望这可以为这个问题提供一些资源。

编辑

为了做到这一点,我跑了RAILS_ENV=production bundle exec rake assets:precompile。然后我用

git add -A
git commit -m "precompiled assets"
git push origin master
git push heroku master
Run Code Online (Sandbox Code Playgroud)

  • @HalilÖzgür 有两个答案。当您输入“RAILS_ENV = Production”时,您正在告诉rails开始使用生产设置,与heroku上相同,因此如果出现错误,您将能够在推送之前看到它。另一方面是,当您在本地编译资产时,您会生成一个“public/assets/manifest”文件。如果 Heroku 看到这一点,他们将不会运行 `rake assets:precompile` 这就是他将它们添加到他的 git 存储库中的原因,因此 heroku 会看到清单文件。 (3认同)