繁体   English   中英

Active Storage 导致 Rails 应用程序在 Heroku 上失败; 在当地工作

[英]Active Storage causing Rails app to fail on Heroku; works locally

我有一个在本地运行良好的 Rails 应用程序。 它不需要任何数据库。 我正在尝试使用 Heroku 部署它,但这是我在日志中获得的关于它为什么不起作用的唯一信息:

2018-09-14T17:27:28.074554+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=calendarizer.herokuapp.com request_id=4da3eec1-23dd-4d1a-ae8f-7b05086d20fc fwd="65.207.79.74" dyno= connect= service= status=503 bytes= protocol=https
2018-09-14T17:27:28.469113+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=calendarizer.herokuapp.com request_id=f079f20e-a9c1-4547-b563-3c2822b89e2d fwd="65.207.79.74" dyno= connect= service= status=503 bytes= protocol=https

我的日志级别设置为调试。 不知道去哪里寻找或如何解决这个问题。

编辑:

我回到日志中,发现了这个:

2018-09-14T17:37:19.872142+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.2.1/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `has_one_attached' for #<Class:0x00000007a055f8> (NoMethodError)

我以前没有听说过 ActiveStorage,但它不是我正在使用的东西(至少不是故意的)。

日志转储:

2018-09-14T17:46:41.000000+00:00 app[api]: Build started by user username@gmail.com 2018-09-14T17:46:59.000000+00:00 app[api]: Build failed -- check your build logs 2018-09-14T17:47:09.445004+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=calendarizer.herokuapp.com request_id=6dca7f6f-3afd-4bcd-b144-f63b85994472 fwd="65.207.79.74" dyno= connect= service= status=503 bytes= protocol=https 2018-09-14T17:47:09.792706+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=calendarizer.herokuapp.com request_id=1818345c-2dfb-4a30-ada6-65ca3bbc04ea fwd="65.207.79.74" dyno= connect= service= status=503 bytes= protocol=https 2018-09-14T17:56:48.278447+00:00 app[api]: Starting process with command `bundle exec rake db:migrate` by user username@gmail.com 2018-09-14T17:56:52.733021+00:00 heroku[run.7080]: Awaiting client 2018-09-14T17:56:52.763164+00:00 heroku[run.7080]: Starting process with command `bundle exec rake db:migrate` 2018-09-14T17:56:52.907308+00:00 heroku[run.7080]: State changed from starting to up 2018-09-14T17:57:00.092474+00:00 heroku[run.7080]: Process exited with status 1 2018-09-14T17:57:00.107737+00:00 heroku[run.7080]: State changed from up to complete 2018-09-14T17:58:27.000000+00:00 app[api]: Build started by user username@gmail.com 2018-09-14T17:58:40.000000+00:00 app[api]: Build failed -- check your build logs 2018-09-14T17:59:08.348804+00:00 app[api]: Starting process with command `bundle exec rake db:migrate` by user username@gmail.com 2018-09-14T17:59:14.334567+00:00 heroku[run.7746]: State changed from starting to up 2018-09-14T17:59:14.252562+00:00 heroku[run.7746]: Awaiting client 2018-09-14T17:59:14.278462+00:00 heroku[run.7746]: Starting process with command `bundle exec rake db:migrate` 2018-09-14T17:59:22.174620+00:00 heroku[run.7746]: Process exited with status 1 2018-09-14T17:59:22.189708+00:00 heroku[run.7746]: State changed from up to complete 2018-09-14T17:59:56.283122+00:00 app[api]: Starting process with command `bundle exec rake db:migrate` by user username@gmail.com 2018-09-14T18:00:05.530380+00:00 heroku[run.7894]: State changed from starting to up 2018-09-14T18:00:05.579669+00:00 heroku[run.7894]: Awaiting client 2018-09-14T18:00:05.633999+00:00 heroku[run.7894]: Starting process with command `bundle exec rake db:migrate` 2018-09-14T18:00:20.779574+00:00 heroku[run.7894]: State changed from up to complete 2018-09-14T18:00:20.763154+00:00 heroku[run.7894]: Process exited with status 1 2018-09-14T18:01:58.718055+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=calendarizer.herokuapp.com request_id=989475e7-affc-41a2-ade6-5cf21ce746a9 fwd="65.207.79.74" dyno= connect= service= status=503 bytes= protocol=https 2018-09-14T18:01:59.041312+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=calendarizer.herokuapp.com request_id=38c77377-2758-4a31-9219-6dcb548a5b1e fwd="65.207.79.74" dyno= connect= service= status=503 bytes= protocol=https

如果要保存某些内容,Heroku 通常希望看到某种数据库(即 pg)运行,我相信在您的应用程序中使用 ActiveRecord 意味着(即使您不打算使用它)。 所以我相信你有两个解决方案。 在您的开发和测试环境中,您可能将 sqlite3 作为您的数据库(您可以查看您的 gemfile),但 Heroku 不适用于 sqlite3。

选项 1:在您的应用程序中禁用 ActiveRecord - 遵循这篇文章: 在 Rails 5.2 中禁用 Active Storage

选项 2:为 heroku 添加一个数据库到您的生产环境,所以很高兴: - 在您的 gemfile 中查看您是否已经有一个生产组

group :production do
  • 如果不添加它
  • 添加 pg gem:

    宝石'pg'

所以你应该在你的 gemfile 中得到这样的东西:

group :production do
  gem 'pg'
end

然后提交并推送到 Heroku。 您可能需要在 Heroku 中重新启动 Dynos,并且您可能还需要在 heroku 上创建数据库文件:

heroku run rails db:create

你现在应该开始运行了。

对我来说,问题是database.yml中的适配器是sqlite3 所以我将config/database.yml的生产部分更改为:

production:
  adapter: postgresql
  encoding: unicodeubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  database: myapp_production
  username: myapp
  password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM