【问题标题】:running app at heroku for the first time and got An error occurred in the application and your page could not be served第一次在heroku上运行应用程序并得到应用程序中发生错误,无法提供您的页面
【发布时间】:2017-01-06 10:30:43
【问题描述】:

我第一次在 heroku 中部署了一个 rails 应用程序,但我遇到了这种错误

2017-01-06T10:26:15.630113+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=salty-brook-61028.herokuapp.com request_id=bdcee548-bb75-4ac0-a3fe-96bc16adaf32 fwd="112.198.103.230" dyno= connect= service= status=503 bytes=
2017-01-06T10:26:17.045896+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=salty-brook-61028.herokuapp.com request_id=37217afd-7781-4f64-8ba3-fc2ad724a4d0 fwd="112.198.103.230" dyno= connect= service= status=503 bytes=

尝试访问该应用程序并显示此消息

An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.

这是使用命令 heroku logs --tails 的日志结果

2017-01-06T11:29:39.413191+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=salty-brook-61028.herokuapp.com request_id=b47de71b-b562-4afd-8625-7082098f25f9 fwd="112.198.73.169" dyno= connect= service= status=503 bytes=
2017-01-06T11:29:41.018749+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=salty-brook-61028.herokuapp.com request_id=f408aa4e-2bab-4a48-9404-56b47ed5e1a9 fwd="112.198.73.169" dyno= connect= service= status=503 bytes=
2017-01-06T11:58:05.415446+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=salty-brook-61028.herokuapp.com request_id=0cf9d492-8e32-49b7-8166-6e983d3442d7 fwd="112.198.73.169" dyno= connect= service= status=503 bytes=

应用程序.rb

require_relative 'boot'

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module MySecondApp
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.
  end
end

生产.rb

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # Code is not reloaded between requests.
  config.cache_classes = true

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both threaded web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.
  config.eager_load = true

  # Full error reports are disabled and caching is turned on.
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Disable serving static files from the `/public` folder by default since
  # Apache or NGINX already handles this.
  config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier
  # config.assets.css_compressor = :sass

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = false

  # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = 'http://assets.example.com'

  # Specifies the header that your server uses for sending files.
  # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

  # Mount Action Cable outside main process or domain
  # config.action_cable.mount_path = nil
  # config.action_cable.url = 'wss://example.com/cable'
  # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  # config.force_ssl = true

  # Use the lowest log level to ensure availability of diagnostic information
  # when problems arise.
  config.log_level = :debug

  # Prepend all log lines with the following tags.
  config.log_tags = [ :request_id ]

  # Use a different cache store in production.
  # config.cache_store = :mem_cache_store

  # Use a real queuing backend for Active Job (and separate queues per environment)
  # config.active_job.queue_adapter     = :resque
  # config.active_job.queue_name_prefix = "my_second_app_#{Rails.env}"
  config.action_mailer.perform_caching = false

  # Ignore bad email addresses and do not raise email delivery errors.
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
  # config.action_mailer.raise_delivery_errors = false

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation cannot be found).
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners.
  config.active_support.deprecation = :notify

  # Use default logging formatter so that PID and timestamp are not suppressed.
  config.log_formatter = ::Logger::Formatter.new

  # Use a different logger for distributed setups.
  # require 'syslog/logger'
  # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

  if ENV["RAILS_LOG_TO_STDOUT"].present?
    logger           = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger = ActiveSupport::TaggedLogging.new(logger)
  end

  # Do not dump schema after migrations.
  config.active_record.dump_schema_after_migration = false
end`

数据库.yml

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3

请帮帮我。

【问题讨论】:

  • 你能发布这个命令的结果吗:heroku logs -t?在您的终端中运行它。
  • 你也有在heroku中运行迁移吗?大多数时候是因为待定的数据库创建和迁移。
  • @sahil,我已经在问题中添加了日志
  • 你运行迁移了吗?
  • 如果您也可以通过屏蔽密码来发布application.rb, production.rb, database.yml,这将很有帮助,或者您也可以查看我在 Heroku 上托管的 my sample app's 配置?

标签: ruby-on-rails heroku


【解决方案1】:

您不能使用 SQLite on heroku... 来修复将 gem 'pg' 添加到 :production 组中的 Gemfile 的问题。

理想情况下,您应该在本地和生产环境中使用相同的数据库,所以我会在本地安装 postgres...

【讨论】:

    猜你喜欢
    • 2019-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-27
    • 2021-11-29
    • 2017-02-25
    • 2017-08-16
    • 1970-01-01
    相关资源
    最近更新 更多