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

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

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

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

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

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

AWS(Amazon Web Services)

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

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

Q&A

0回答

736閲覧

Railsでフォローボタンの表示ができない。

amby

総合スコア40

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

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

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

AWS(Amazon Web Services)

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

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

0グッド

1クリップ

投稿2020/11/23 13:47

内容

Railsで開発しているアプリをAWSにデプロイしています。ユーザーフォロー画面にいくと「We're sorry, but something went wrong.」のエラーが出ます。
ログを覗くと「ActionView::Template::Error (Mysql2::Error: Table 'portfolio_development.relationships' doesn't exist: SHOW FULL FIELDS FROM relationships):」とエラーメッセージが出てきます。
下記の記事を参考に修正しようとしましたが、修正できませんでした。
https://qiita.com/Jwataru/items/7b840be38d4279224245
お力お借りしたいです。

エラーメッセージ

ActionView::Template::Error (Mysql2::Error: Table 'portfolio_development.relationships' doesn't exist: SHOW FULL FIELDS FROM `relationships`): F, [2020-11-23T13:36:11.274578 #3562] FATAL -- : [2fc4ee12-7951-44f4-a7e5-922da7e755af] 1: <% unless current_user == user %> [2fc4ee12-7951-44f4-a7e5-922da7e755af] 2: <%if current_user.following?(user) %> [2fc4ee12-7951-44f4-a7e5-922da7e755af] 3: <%= form_with(model: current_user.relationships.find_by(follow_id: user.id), local: true, method: :delete) do |f| %> [2fc4ee12-7951-44f4-a7e5-922da7e755af] 4: <%= hidden_field_tag :follow_id, user.id %> [2fc4ee12-7951-44f4-a7e5-922da7e755af] 5: <%= f.submit 'フォロー中', class: 'btn btn-primary btn-block' %> F, [2020-11-23T13:36:11.274605 #3562] FATAL -- : [2fc4ee12-7951-44f4-a7e5-922da7e755af] F, [2020-11-23T13:36:11.274628 #3562] FATAL -- : [2fc4ee12-7951-44f4-a7e5-922da7e755af] app/models/user.rb:34:in `following?'

users.hrml.erb

<div class = "card col-lg-5 col-md-7 user_card_main"> <div class= "user_card row"> <div class ="user_card_left"> <% if user.image? %> <%= image_tag user.image.url, class: "rounded-circle", height:"100px" %> <% else %> <%= image_tag "/assets/default.png", class: "rounded-circle", height:"100px" %> <% end %> <div class="follow_button user_card_follow_btn"> <%= render 'relationships/follow_button', user: user %> </div> </div> <div class ="user_card_right"> <table class="table"> <tr> <td>名前   :</td> <td><%=link_to user.name, user_path(user) %></td> </tr> <tr> <td>性別   :</td> <td><%= user.sex %></td> </tr> <tr> <td>年齢   :</td> <td><%= user.age %></td> </tr> <tr> <td>ポジション:</td> <td><%= user.position %></td> </tr> </table> </div> </div> </div>

フォローボタン部分

<% unless current_user == user %> <%if current_user.following?(user) %> <%= form_with(model: current_user.relationships.find_by(follow_id: user.id), local: true, method: :delete) do |f| %> <%= hidden_field_tag :follow_id, user.id %> <%= f.submit 'フォロー中', class: 'btn btn-primary btn-block' %> <% end %> <% else %> <%= form_with(model: current_user.relationships.build, local: true) do |f| %> <%= hidden_field_tag :follow_id, user.id %> <%= f.submit 'フォローする', class: 'btn btn-warning btn-block' %> <% end %> <% end %> <% end %>

usersモデル

class User < ApplicationRecord validates :name, presence: true, length: { maximum: 50 } validates :email, presence: true, length: { maximum: 255 }, format: { with: /\A[\w+\-.]+@[a-z\d\-.]+.[a-z]+\z/i }, uniqueness: { case_sensitive: false } has_secure_password has_many :microposts has_many :relationships has_many :followings, through: :relationships, source: :follow has_many :reverses_of_relationship, class_name: 'Relationship', foreign_key: 'follow_id' has_many :followers, through: :reverses_of_relationship, source: :user has_many :likes has_many :likings, through: :likes, source: :micropost has_many :joins has_many :joinings, through: :joins, source: :micropost has_many :comments, dependent: :destroy THUMBNAIL_SIZE = [300, 300] mount_uploader :image, ImageUploader def follow(other_user) unless self == other_user self.relationships.find_or_create_by(follow_id: other_user.id) end end def unfollow(other_user) relationship = self.relationships.find_by(follow_id: other_user.id) relationship.destroy if relationship end def following?(other_user) self.followings.include?(other_user) end def like_it(other_micropost) self.likes.find_or_create_by(micropost_id: other_micropost.id) end def unlike_it(other_micropost) favorite = self.likes.find_by(micropost_id: other_micropost.id) favorite.destroy if favorite end def liking?(other_micropost) self.likings.include?(other_micropost) end def joining_event(other_micropost) self.joins.find_or_create_by(micropost_id: other_micropost.id) end def not_joining_event(other_micropost) join = self.joins.find_by(micropost_id: other_micropost.id) join.destroy if join end def joining?(other_micropost) self.joinings.include?(other_micropost) end end

その他

使っているrailsは5.2.4.3です。
フォローボタンを非表示にしたらエラーはなくなりました。
開発環境ではうまく表示されていました。
rails db:migrateをはしましたが治りませんでした。

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

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

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

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

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

saoyagi2

2020/11/25 06:24

エラーメッセージは「portfolio_development というデータベースに relationships というテーブルが無い」という意味です。 デプロイということから本番環境でしょうから、開発用データベースは無くて当然だと思います。とすると rails を実行時に環境の指定がうまくいってないのではないかと推測します。rails を実行してるコマンドを追記してもらえますでしょうか。RAILS_ENV はどのように指定していますでしょうか。 また database.yml も秘密情報はマスクしたうえで追記をお願いいたします。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問