実現したいこと
AWSで設定し、webサーバーに自作ページが表示されるように設定したい。
前提
・自作ページはrails で作成しています。
・ローカルではページが表示できています。
・nginxの起動(自動起動も)済み
・puma起動済み
発生している問題・エラーメッセージ
ログの内容(更新:2024/04/06)
[ec2-user@ip-(プライベートIP) *]$ sudo tail -f log/production.log I, [2024-04-05T16:08:34.781147 #3565] INFO -- : [20281883-dea3-4002-9f2a-4666b6eeddc5] Started GET "/shops/accommodation" for 14.11.8.34 at 2024-04-05 16:08:34 +0000 I, [2024-04-05T16:08:34.781885 #3565] INFO -- : [20281883-dea3-4002-9f2a-4666b6eeddc5] Processing by User::ShopsController#accommodation as HTML I, [2024-04-05T16:08:34.807297 #3565] INFO -- : [20281883-dea3-4002-9f2a-4666b6eeddc5] Completed 500 Internal Server Error in 25ms (ActiveRecord: 10.6ms | Allocations: 1228) F, [2024-04-05T16:08:34.808040 #3565] FATAL -- : [20281883-dea3-4002-9f2a-4666b6eeddc5] [20281883-dea3-4002-9f2a-4666b6eeddc5] NoMethodError (undefined method `shops' for nil:NilClass @shops = target_genre.shops ^^^^^^): [20281883-dea3-4002-9f2a-4666b6eeddc5] [20281883-dea3-4002-9f2a-4666b6eeddc5] app/controllers/user/shops_controller.rb:5:in `accommodation' I, [2024-04-05T16:09:23.258541 #3565] INFO -- : [9be6b26d-3d18-46d0-902f-b926c87848e2] Started GET "/shops/shopping_mall" for 14.11.8.34 at 2024-04-05 16:09:23 +0000 I, [2024-04-05T16:09:23.259280 #3565] INFO -- : [9be6b26d-3d18-46d0-902f-b926c87848e2] Processing by User::ShopsController#shopping_mall as HTML I, [2024-04-05T16:09:23.262093 #3565] INFO -- : [9be6b26d-3d18-46d0-902f-b926c87848e2] Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.6ms | Allocations: 1052) F, [2024-04-05T16:09:23.262978 #3565] FATAL -- : [9be6b26d-3d18-46d0-902f-b926c87848e2] [9be6b26d-3d18-46d0-902f-b926c87848e2] NoMethodError (undefined method `shops' for nil:NilClass @shops = target_genre.shops ^^^^^^): [9be6b26d-3d18-46d0-902f-b926c87848e2] [9be6b26d-3d18-46d0-902f-b926c87848e2] app/controllers/user/shops_controller.rb:11:in `shopping_mall' I, [2024-04-05T16:09:43.407816 #3565] INFO -- : [57dedbb7-8971-4bb0-9aa9-16ebd36df769] Started GET "/shops/activity" for 14.11.8.34 at 2024-04-05 16:09:43 +0000 I, [2024-04-05T16:09:43.408537 #3565] INFO -- : [57dedbb7-8971-4bb0-9aa9-16ebd36df769] Processing by User::ShopsController#activity as HTML I, [2024-04-05T16:09:43.411274 #3565] INFO -- : [57dedbb7-8971-4bb0-9aa9-16ebd36df769] Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.5ms | Allocations: 1089) F, [2024-04-05T16:09:43.411986 #3565] FATAL -- : [57dedbb7-8971-4bb0-9aa9-16ebd36df769] [57dedbb7-8971-4bb0-9aa9-16ebd36df769] NoMethodError (undefined method `shops' for nil:NilClass @shops = target_genre.shops ^^^^^^): [57dedbb7-8971-4bb0-9aa9-16ebd36df769] [57dedbb7-8971-4bb0-9aa9-16ebd36df769] app/controllers/user/shops_controller.rb:17:in `activity'
上記ログにて、'shops'がnilだと言われていますが、Genreの中身を調べた時のログは下記になります。
ec2-user:~/environment/* (main) $ rails c Running via Spring preloader in process 17562 Loading development environment (Rails 6.1.7.6) 3.1.2 :001 > Genre.all (1.8ms) SELECT sqlite_version(*) Genre Load (1.0ms) SELECT "genres".* FROM "genres" => [#<Genre:0x00007f1fd9941c90 id: 1, name: "宿泊施設", created_at: Thu, 21 Mar 2024 19:48:53.728896000 JST +09:00, updated_at: Thu, 21 Mar 2024 19:48:53.728896000 JST +09:00>, #<Genre:0x00007f1fd9930c60 id: 2, name: "ショッピングモール", created_at: Thu, 21 Mar 2024 19:48:53.749879000 JST +09:00, updated_at: Thu, 21 Mar 2024 19:48:53.749879000 JST +09:00>, #<Genre:0x00007f1fd9930b98 id: 3, name: "アクティビティ", created_at: Thu, 21 Mar 2024 19:48:53.763834000 JST +09:00, updated_at: Thu, 21 Mar 2024 19:48:53.763834000 JST +09:00>]
そしてエラーが発生しているapp/controllers/user/shops_controller.rb内のコードも下記に記載します。
class User::ShopsController < ApplicationController def accommodation target_genre = Genre.find_by(name: "宿泊施設") @shops = target_genre.shops @revue = Revue.new end def shopping_mall target_genre = Genre.find_by(name: "ショッピングモール") @shops = target_genre.shops @revue = Revue.new end def activity target_genre = Genre.find_by(name: "アクティビティ") @shops = target_genre.shops @revue = Revue.new end def show end end
ログで出ているINFOの内容も分かりません。
教えてほしいです。
回答1件
あなたの回答
tips
プレビュー