【问题标题】:Asset Pipeline failing when deploying to Heroku部署到 Heroku 时资产管道失败
【发布时间】:2013-09-04 23:32:52
【问题描述】:

当我部署到 Heroku 时,我收到以下错误消息:

Connecting to database specified by DATABASE_URL
   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?

奇怪的是,这只是在我将gem 'impressionist' 添加到 Gemfile 之后才开始发生的。本地没有任何问题。注释掉 gem 可以解决部署问题。

从 Heroku 收到的错误是 well documented,但那里没有任何线索让我知道是什么导致了失败。

The Impressionist gem 相当受欢迎,我还没有看到任何类似的问题源于它,所以我怀疑 gem 是问题的根源。

更新

这是完整的 Gemfile,只是为了表明它是一个在部署中运行良好的普通应用程序(直到添加了上述 gem)。

source 'https://rubygems.org'

gem 'rails', '3.2.13'
gem 'bcrypt-ruby', '3.0.1'
gem 'jquery-rails', '2.2.1'
gem 'impressionist'
# gem 'will_paginate'

group :assets do
  gem 'sass-rails',   '~> 3.2.6'
  gem 'uglifier', '>= 1.3.0'
  gem 'jquery-ui-rails'
end

group :development, :test do
  gem 'quiet_assets'
  gem 'webrick', '~> 1.3.1'
  gem 'sqlite3', '1.3.7'
  gem 'hirb'
end

group :production do
  gem 'thin'
  gem 'pg', '0.12.2'
end

【问题讨论】:

  • 您是否添加了资产指南中提到的 user-env-compile 标志? devcenter.heroku.com/articles/rails-asset-pipeline
  • 你的 postgresql 服务器在运行吗? ps aux | grep postgres
  • @friism 不,我没有。正如您在更新中看到的那样,该应用程序正常运行,所以我不知道这是否是一个有意义的解决方案?
  • @Vimsha 在本地我运行 SQLite3。如果我删除 gem,应用程序和数据库运行良好。

标签: ruby-on-rails heroku rubygems bundler asset-pipeline


【解决方案1】:

“问题”是 Impressionist 即时设置数据库配置,因此它需要加载数据库适配器。让我们以 ActiveRecord 为例。当它尝试加载 ActiveRecord::Base 时,它​​会引发 Heroku 用该消息通知您的异常,因为您尚未连接到数据库。 Devise 遇到过这个问题 plataformatec/devise#1339

我添加了 cancan gem 并删除了印象派,它引发了同样的错误。

还好有解决办法:

# config/application.rb
# Forces application to not load models or access the DB when precompiling
# assets
config.assets.initialize_on_precompile = false

谢谢:)

【讨论】:

    【解决方案2】:

    我建议在该 gem 的 GitHub 项目上提交问题。很可能它正在尝试使用初始化过程连接到数据库,并且由于该阶段数据库不可用,因此它失败了。

    您可以通过将此行添加到您的 config/environments/production.rb 文件中来解决此问题:

     config.assets.initialize_on_precompile = false
    

    【讨论】:

    • 不幸的是,添加上面的行并没有解决它。我现在在 GitHub 上提交了一个问题。谢谢!
    【解决方案3】:

    在您的 production.rb 文件中更改它

    config.assets.compile = false
    

    然后在本地预编译资产

    RAILS_ENV=production bundle exec rake assets:precompile
    

    将创建一个 public/assets 目录。在此目录中,您将找到一个 manifest.yml,其中包含 Rails 3 中已编译资产的 md5sum。在 Rails 4 中,该文件将为 manifest-.json。将 public/assets 添加到您的 git 存储库将使其可供 Heroku 使用。

    git add public/assets
    git commit -m "vendor compiled assets"
    

    之后推送代码

    【讨论】:

      猜你喜欢
      • 2013-03-03
      • 1970-01-01
      • 2021-04-06
      • 1970-01-01
      • 2012-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-27
      相关资源
      最近更新 更多