将Rails 4部署到Heroku,收到错误

问题描述 投票:0回答:2

我已经完成了Rails 4的示例项目,在本地运行得很好,但是当我将应用程序推向Heroku之后,它没有按预期运行。

细节:

An error occurred in the application and your page could not be served. Please try again in a few moments.

我检查了heroku logs,不知道。但根据日志,我想这与独角兽有关。有人可以帮忙吗?我将不胜感激!

Databse.yml文件

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5

development:
  <<: *default
  database: devep00

test:
  <<: *default
  database: testp00
ruby-on-rails postgresql heroku
2个回答
1
投票

您需要具有Unicorn的配置文件,请创建一个包含以下内容的文件,并将其放入config/unicorn.rb

# config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
preload_app true

before_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end

此处有更多详细信息https://devcenter.heroku.com/articles/rails-unicorn#config


0
投票

正如@charinten指出的那样-如果尚未将其发布到config下的unicorn.rb文件中(请在我发布我的答案后再看答案)

worker_processes 4
timeout 30
preload_app true

before_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end
© www.soinside.com 2019 - 2024. All rights reserved.