Open yuyanegishi opened 5 years ago
@user = Relationship.find(params[:id]).followed
Relationship.find(params[:id])
Relationクラスのインスタンス.followed
class Relationship < ApplicationRecord
belongs_to :follower, class_name: "User"
belongs_to :followed, class_name: "User"
validates :follower_id, presence: true
validates :followed_id, presence: true
end
current_user.unfollow(@user)
# ユーザーをフォロー解除する
def unfollow(other_user)
active_relationships.find_by(followed_id: other_user.id).destroy
end
active_relationships.find_by(followed_id: other_user.id)