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

时间:2018-09-14 17:30:20

标签: ruby-on-rails heroku

我有一个在本地运行良好的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

我的日志级别设置为DEBUG。不知道在其他地方或如何解决这个问题。

编辑:

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

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

2 个答案:

答案 0 :(得分:0)

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

选项1:    在您的应用中禁用ActiveRecord-这篇文章:Disable Active Storage in Rails 5.2

选项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

您应该现在就开始运行。

答案 1 :(得分:0)

对我来说,问题是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'] %>