質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

解決済

1回答

168閲覧

デプロイ後に一部ページでWe're sorry, but something went wrong.エラーが出る

pag_jiro

総合スコア10

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2024/04/07 07:12

編集2024/04/07 12:36

実現したいこと

We're sorry, but something went wrong.のエラーを解消

前提

・ページはrailsと一部にJSを使用(今回はrailsのエラーのはず)
・デプロイは完了済み

発生している問題・エラーメッセージ

テンプレートファイルのエラーだと言われていて、 app/views/user/customers/show.html.erbファイルの31行目のエラーだということはわかります。
内容的には、"testimonials"が未定義メソッドだという内容だと思います。
しかし、マイグレーションファイルに記述はありましたし、ローカルでは問題なく表示されています。

以下ログ内容です。

I, [2024-04-07T06:58:34.502448 #3446] INFO -- : [9b25652e-9d7d-4d3f-92f5-1ece706144fa] Started GET "/customer/my_page" for 14.11.8.34 at 2024-04-07 06:58:34 +0000 I, [2024-04-07T06:58:34.503179 #3446] INFO -- : [9b25652e-9d7d-4d3f-92f5-1ece706144fa] Processing by User::CustomersController#show as HTML I, [2024-04-07T06:58:34.515904 #3446] INFO -- : [9b25652e-9d7d-4d3f-92f5-1ece706144fa] Rendered user/customers/show.html.erb within layouts/application (Duration: 10.0ms | Allocations: 4967) I, [2024-04-07T06:58:34.516082 #3446] INFO -- : [9b25652e-9d7d-4d3f-92f5-1ece706144fa] Rendered layout layouts/application.html.erb (Duration: 10.2ms | Allocations: 4997) I, [2024-04-07T06:58:34.516305 #3446] INFO -- : [9b25652e-9d7d-4d3f-92f5-1ece706144fa] Completed 500 Internal Server Error in 13ms (ActiveRecord: 0.6ms | Allocations: 5650) F, [2024-04-07T06:58:34.517322 #3446] FATAL -- : [9b25652e-9d7d-4d3f-92f5-1ece706144fa] [9b25652e-9d7d-4d3f-92f5-1ece706144fa] ActionView::Template::Error (undefined method `testimonials' for #<User id: 1, created_at: "2024-04-06 12:36:28.731079000 +0900", updated_at: "2024-04-06 12:36:28.731079000 +0900", email: "111@111", nickname: "111">): [9b25652e-9d7d-4d3f-92f5-1ece706144fa] 28: [9b25652e-9d7d-4d3f-92f5-1ece706144fa] 29: <tr> [9b25652e-9d7d-4d3f-92f5-1ece706144fa] 30: <td style="width:45%" class="table-active">自己紹介文</td> [9b25652e-9d7d-4d3f-92f5-1ece706144fa] 31: <td><%= @user.testimonials %></td> [9b25652e-9d7d-4d3f-92f5-1ece706144fa] 32: </tr> [9b25652e-9d7d-4d3f-92f5-1ece706144fa] 33: [9b25652e-9d7d-4d3f-92f5-1ece706144fa] 34: </tbody> [9b25652e-9d7d-4d3f-92f5-1ece706144fa] [9b25652e-9d7d-4d3f-92f5-1ece706144fa] app/views/user/customers/show.html.erb:31

試したこと

・EC2の再起動
・git pull→マイグレーションの動作

追記

db/schema.rbのusers

create_table "users", force: :cascade do |t| t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.string "nickname", null: false t.string "testimonials", default: "", null: false t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end

app/models/users.rb

class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable has_one_attached :image # has_many :likes, dependent: :destroy has_many :niced_tweets, through: :nices, source: :tweet def already_niced?(tweet) self.nices.exists?(tweet_id: tweet.id) end has_many :inquiry has_many :revues def already_revued?(shop) self.revues.exists?(shop_id: shop.id) end # フォローした人を作る has_many :follows, class_name: "Follow", foreign_key: "user_follower_id", dependent: :destroy # フォローした人の一覧 has_many :user_followings, through: :follows, source: :user_followed #フォローされた人の中間テーブル has_many :reverse_of_follows, class_name: "Follow", foreign_key: "user_followed_id", dependent: :destroy #フォローされた人に一覧 has_many :user_followers, through: :reverse_of_follows, source: :user_follower # フォローしたときの処理 def user_follow(user) #byebug follows.find_or_create_by(user_followed_id: user.id) end # フォローを外すときの処理 def user_unfollow(user) follows.find_by(user_followed_id: user.id)&.destroy end # フォローしているか判定 def user_following?(user) user_followings.include?(user) end def get_image(width, height) unless image.attached? file_path = Rails.root.join('app/assets/images/no_image.jpg') image.attach(io: File.open(file_path), filename: 'default-image.jpg', content_type: 'image/jpeg') end image.variant(resize: "#{width}x#{height}").processed end # 退会時の削除内容 has_many :nices, :dependent => :destroy has_many :tweets , :dependent => :destroy has_many :inquiries , :dependent => :destroy has_many :revues , :dependent => :destroy end

RAILS_ENV=production rails c の結果

irb(main):001:0> User.column_names.sort => ["created_at", "email", "encrypted_password", "id", "nickname", "remember_created_at", "reset_password_sent_at", "reset_password_token", "updated_at"] irb(main):002:0>

RAILS_ENV=production rails db:migrate の結果
一度git pullして最新にし、RAILS_ENV=production rails db:migrateを実行したログです。
きっと実行したときに下にログが出るはずなのですが、何も出ずに入力に進んでしまいます。

[ec2-user@ip-(プライベートIP) *]$ git pull origin main From https://github.com/(名前)/* * branch main -> FETCH_HEAD Already up to date. [ec2-user@ip-(プライベートIP) *]$ RAILS_ENV=production rails db:migrate [ec2-user@ip-(プライベートIP) *]$

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

winterboum

2024/04/07 09:31 編集

ちょっと気になる記述があるのでその確認をしたいです。 db/schema.rb のusers の所と app/models/user.rb を 載せてください db/schema.rb は deploy先のやつを。 localのではなく
pag_jiro

2024/04/07 09:49

返信ありがとうございます。 指定箇所を追記致しました。 確認よろしくお願いします。
winterboum

2024/04/07 11:57

気になるところは問題無かったです。 さて、、、、
winterboum

2024/04/07 11:58

RAILS_ENV=production rails c して、 User.column_names.sort の結果見せてください
pag_jiro

2024/04/07 12:10

返信ありがとうございます。 記事に追記致しました。 確認お願いします。
guest

回答1

0

ベストアンサー

RAILS_ENV=production rails c で User.column_names.sort した結果を見ると、testimonials がありません。
db/schema.rb にはあるのに。
ということは デプロイ先にもdevelopment環境持ち込んでませんか?
db/schema.rb は development で db:migrateした結果。productionではmigreteしていないのが残ってる。
RAILS_ENV=production rails db:migrate してみてください。

不安要素は、
そういう状態でサーバ立ち上げると migrationしてないよ、というエラーが出たのではなかったか、、、、それ出ているような気配がない。。。。

投稿2024/04/07 12:25

winterboum

総合スコア23351

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

pag_jiro

2024/04/07 12:37

回答ありがとうございます。 試したログを記事に追記させて頂きました。 どうしても実行後のログがでずに、入力画面に進むといった状況です。
winterboum

2024/04/07 13:09

db:migrate の結果を見ると既にmigrationは終わっていた、ということを示してます。 にもかかわらず User.column_names に testimonials が無いということは、testimonials を追加する migration が サーバに届いていないということですね。 db:schema.rbに有るのは localのがcommitされてそれが届いた、ということのようで。 サーバで RAILS_ENV=production rails db:migrate:status し、 local での rails db:migrate:status と比較してください。多分 サーバでは ad_column : testimonials な migrationが無いのでは。 local で git status すると、db:migrate に 追跡されていないファイル があるのでは?
pag_jiro

2024/04/07 13:15

回答あろがとうございます。 こちらでマイグレーションのリセットを行ったところ、何故か反映されるようになっていました。 しかし、別のページで問題が起きてしまったので、まだ修正はかかりそうです。 ここまで返信頂きありがとうございました。 ベストアンサーに選ばせて頂きます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問