我的 Heroku 应用程序不会检索与 Rails 中创建的数据库关联的页面。它可以在服务器本地运行,但部署后就不能运行

发布于 2025-01-11 14:44:17 字数 4710 浏览 0 评论 0原文

该数据库称为“游戏”。我让它在一个部分中被调用,然后在称为“时间表”的主视图中呈现。

这就是它崩溃的地方

2022-03-04T13:54:59.252562+00:00 app[web.1]: F, [2022-03-04T13:54:59.252477 #4] FATAL -- : [8695d016-d4be-4ece-b9ae-a31c6546608d]   
2022-03-04T13:54:59.252564+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d] ActionView::Template::Error (undefined method `[]' for nil:NilClass):
2022-03-04T13:54:59.252564+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d]     1: <a href="games/game0"> 
2022-03-04T13:54:59.252565+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d]     2:     <div id= "match">
2022-03-04T13:54:59.252566+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d]     3:         <div id= "team"> 
2022-03-04T13:54:59.252566+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d]     4:             <div id= "name"> <%= @games[0]["local_team"]%> </div>
2022-03-04T13:54:59.252567+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d]     5:             <div id= "logos"> <%= image_tag @games[0]["local_logos"] %></div>
2022-03-04T13:54:59.252568+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d]     6:             <div id= "scores"> <%= @games[0]["localteam_score"] %> </div>
2022-03-04T13:54:59.252569+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d]     7:         </div> 
2022-03-04T13:54:59.252569+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d]   
2022-03-04T13:54:59.252570+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d] app/views/schedule/_match.html.erb:4
2022-03-04T13:54:59.252571+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d] app/views/schedule/schedule.html.erb:4
2022-03-04T13:54:59.252783+00:00 heroku[router]: at=info method=GET path="/schedule" host=ratedapp.herokuapp.com request_id=8695d016-d4be-4ece-b9ae-a31c6546608d fwd="66.211.28.242" dyno=web.1 connect=4ms service=12ms status=500 bytes=1827 protocol=https

似乎它无法从我的 Heroku 数据库中检索信息。我已经运行了“heroku run Rails db:migrate”。

外观,

default: &default
  adapter: postgresql
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 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

这是我的 database.yml以及 Gemfile 的

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem 'rails',                      '6.1.4.1'
gem 'bcrypt',                     '3.1.13'
gem 'image_processing',           '1.9.3'
gem 'mini_magick',                '4.9.5'
gem 'active_storage_validations', '0.8.9'
gem 'faker',                      '2.11.0'
gem 'will_paginate',              '3.3.0'
gem 'bootstrap-will_paginate',    '1.0.0'
gem 'bootstrap-sass',             '3.4.1'
gem 'puma',                       '5.3.1'
gem 'sass-rails',                 '6.0.0'
gem 'webpacker',                  '5.4.0'
gem 'turbolinks',                 '5.2.1'
gem 'rest-client',                '2.1'
gem 'sportmonks'
gem 'dotenv'
gem 'jbuilder',                   '2.10.0'
gem 'bootsnap',                   '1.7.2', require: false

group :development, :test do
  gem 'sqlite3', '1.4.2'
  gem 'byebug',  '11.1.3', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  gem 'web-console',        '4.1.0'
  gem 'rack-mini-profiler', '2.3.1'
  gem 'listen',             '3.4.1'
  gem 'spring',             '2.1.1'
end

group :test do
  gem 'capybara',                 '3.35.3'
  gem 'selenium-webdriver',       '3.142.7'
  gem 'webdrivers',               '4.6.0'
  gem 'rails-controller-testing', '1.0.5'
  gem 'minitest',                 '5.11.3'
  gem 'minitest-reporters',       '1.3.8'
  gem 'guard',                    '2.16.2'
  gem 'guard-minitest',           '2.4.6'
end

group :production do
  gem 'pg',         '1.2.3'
  gem 'aws-sdk-s3', '1.87.0', require: false
end

我一整天都在尝试部署它,最后将其范围缩小到数据库问题。我这周才开始在 Rails 内部使用数据库,所以我在寻找下一步应该进行故障排除时遇到了问题。

我尝试将数据库迁移到 Heroku 并阅读这些链接

https://devcenter.heroku.com/文章/sqlite3

https://devcenter.heroku.com/articles/getting-started-with-rails6

但我仍然陷入死胡同,没有任何效果。除了与数据库绑定的页面之外,我的应用程序的所有其他部分都可以工作。

The database is called "games". I have it being called in a partial that then is rendered in the primary view called "schedule".

Here is where it's breaking down

2022-03-04T13:54:59.252562+00:00 app[web.1]: F, [2022-03-04T13:54:59.252477 #4] FATAL -- : [8695d016-d4be-4ece-b9ae-a31c6546608d]   
2022-03-04T13:54:59.252564+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d] ActionView::Template::Error (undefined method `[]' for nil:NilClass):
2022-03-04T13:54:59.252564+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d]     1: <a href="games/game0"> 
2022-03-04T13:54:59.252565+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d]     2:     <div id= "match">
2022-03-04T13:54:59.252566+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d]     3:         <div id= "team"> 
2022-03-04T13:54:59.252566+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d]     4:             <div id= "name"> <%= @games[0]["local_team"]%> </div>
2022-03-04T13:54:59.252567+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d]     5:             <div id= "logos"> <%= image_tag @games[0]["local_logos"] %></div>
2022-03-04T13:54:59.252568+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d]     6:             <div id= "scores"> <%= @games[0]["localteam_score"] %> </div>
2022-03-04T13:54:59.252569+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d]     7:         </div> 
2022-03-04T13:54:59.252569+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d]   
2022-03-04T13:54:59.252570+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d] app/views/schedule/_match.html.erb:4
2022-03-04T13:54:59.252571+00:00 app[web.1]: [8695d016-d4be-4ece-b9ae-a31c6546608d] app/views/schedule/schedule.html.erb:4
2022-03-04T13:54:59.252783+00:00 heroku[router]: at=info method=GET path="/schedule" host=ratedapp.herokuapp.com request_id=8695d016-d4be-4ece-b9ae-a31c6546608d fwd="66.211.28.242" dyno=web.1 connect=4ms service=12ms status=500 bytes=1827 protocol=https

It seems as though it can't retrieve the information from my database on Heroku. I've run "heroku run rails db:migrate".

Here is how my database.yml looks

default: &default
  adapter: postgresql
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 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

As well as my Gemfile

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem 'rails',                      '6.1.4.1'
gem 'bcrypt',                     '3.1.13'
gem 'image_processing',           '1.9.3'
gem 'mini_magick',                '4.9.5'
gem 'active_storage_validations', '0.8.9'
gem 'faker',                      '2.11.0'
gem 'will_paginate',              '3.3.0'
gem 'bootstrap-will_paginate',    '1.0.0'
gem 'bootstrap-sass',             '3.4.1'
gem 'puma',                       '5.3.1'
gem 'sass-rails',                 '6.0.0'
gem 'webpacker',                  '5.4.0'
gem 'turbolinks',                 '5.2.1'
gem 'rest-client',                '2.1'
gem 'sportmonks'
gem 'dotenv'
gem 'jbuilder',                   '2.10.0'
gem 'bootsnap',                   '1.7.2', require: false

group :development, :test do
  gem 'sqlite3', '1.4.2'
  gem 'byebug',  '11.1.3', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  gem 'web-console',        '4.1.0'
  gem 'rack-mini-profiler', '2.3.1'
  gem 'listen',             '3.4.1'
  gem 'spring',             '2.1.1'
end

group :test do
  gem 'capybara',                 '3.35.3'
  gem 'selenium-webdriver',       '3.142.7'
  gem 'webdrivers',               '4.6.0'
  gem 'rails-controller-testing', '1.0.5'
  gem 'minitest',                 '5.11.3'
  gem 'minitest-reporters',       '1.3.8'
  gem 'guard',                    '2.16.2'
  gem 'guard-minitest',           '2.4.6'
end

group :production do
  gem 'pg',         '1.2.3'
  gem 'aws-sdk-s3', '1.87.0', require: false
end

I have been trying to get this to deploy all day, and finally narrowed it down to it being a database issue. I've only started working with DB's inside of Rails this week, so I'm having issues finding what my next step should be to troubleshoot.

I've tried migrating the database to Heroku and read through these links

https://devcenter.heroku.com/articles/sqlite3

https://devcenter.heroku.com/articles/getting-started-with-rails6

but I'm still running into a dead end and nothing has worked. All other parts of my app work except the pages that are tied to a database in anyway.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文