Skip to content

Commit

Permalink
追加
Browse files Browse the repository at this point in the history
  • Loading branch information
a-saki committed Jul 9, 2016
1 parent e7a605d commit f35c08d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 8 additions & 6 deletions app/controllers/relationships_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
class RelationshipsController < ApplicationController
def create
@user = User.find(params[:followed_id])
current_user.follow(@user)
end

def destroy
before_action :logged_in_user

def create
@user = User.find(params[:followed_id])
current_user.follow(@user)
end

def destroy
@user = current_user.following_relationships.find(params[:id]).followed
current_user.unfollow(@user)
end
Expand Down
3 changes: 3 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class User < ActiveRecord::Base
has_many :following_relationships, class_name: 'Relationship', foreign_key: 'follower_id', dependent: :destroy
has_many :following_users, through: :following_relationships, source: :followed

has_many :follower_relationships, class_name: 'Relationship', foreign_key: 'followed_id', dependent: :destroy
has_many :follower_users, through: :follower_relationships, source: :follower


#メソッドの追加
#他のユーザーをフォローする
Expand Down

0 comments on commit f35c08d

Please sign in to comment.