【问题标题】:Tried several fixes: Heroku/Rails 4 Assets Precompile Error尝试了几个修复:Heroku/Rails 4 Assets Precompile Error
【发布时间】:2013-06-05 15:03:20
【问题描述】:

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

跟随this线程,我跑了

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

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

RAILS_ENV=production bundle exec rake assets:precompile

确实如此。

我也跟着this小费,设置

config.assets.initialize_on_precompile = false

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

此外,在this 问题之后,我已确保我已安装 heroku gem:

gem 'rails_log_stdout',           github: 'heroku/rails_log_stdout'
gem 'rails3_serve_static_assets', github: 'heroku/rails3_serve_static_assets'

然后我通过关注this heroku article 确保我的路径中有bin

然后我确保我遵循了 heroku 上的“Rails 4.x.x 入门”article

我还关注了this question 的另一个答案,并将以下内容放在application.rbproduction.rb

config.serve_static_assets = true

这是我在运行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?

似乎config.assets.initialize_on_precompile = false 应该可以工作,因为它似乎在预编译期间尝试加载生产数据库。

我已经进行了所有这些更改,并且它们已被推送到 git 中。现在我应该尝试什么?

【问题讨论】:

    标签: heroku asset-pipeline ruby-on-rails-4


    【解决方案1】:

    好吧,对不起。我想我没有推动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
    

    【讨论】:

    • Rails 4 中也没有initialize_on_precompile
    • 你能解释一下你是如何解决“我想我没有推动 RAILS_ENV=production bundle exec rake assets:precompile.”的影响吗?最好是对于一个 rails noob :)
    • @HalilÖzgür 有两个答案。当您输入RAILS_ENV=production 时,您是在告诉rails 开始使用生产设置,就像在heroku 上一样,因此如果出现错误,您将能够在推送之前看到它。另一部分是当您在本地编译资产时,您会生成一个public/assets/manifest 文件。如果 heroku 看到这一点,他们将不会运行 rake assets:precompile 这就是他将它们添加到他的 git repo 的原因,因此 heroku 会看到清单文件。
    猜你喜欢
    • 2014-10-25
    • 2018-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-10
    • 2014-05-21
    • 2015-11-14
    • 1970-01-01
    相关资源
    最近更新 更多