質問編集履歴
3
コード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,4 +8,30 @@
|
|
8
8
|
```
|
9
9
|
|
10
10
|
しかしこれだとエラーになるようで、
|
11
|
-
どのようにすれば取り出せますか?
|
11
|
+
どのようにすれば取り出せますか?
|
12
|
+
|
13
|
+
```
|
14
|
+
class User
|
15
|
+
|
16
|
+
follow 関連
|
17
|
+
|
18
|
+
has_many :relationships
|
19
|
+
has_many :followings, through: :relationships, source: :follow
|
20
|
+
has_many :reverse_of_relationships, class_name: 'Relationship', foreign_key: 'follow_id'
|
21
|
+
has_many :followers, through: :reverse_of_relationships, source: :user
|
22
|
+
|
23
|
+
def follow(other_user)
|
24
|
+
unless self == other_user
|
25
|
+
self.relationships.find_or_create_by(follow_id: other_user.id)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def unfollow(other_user)
|
30
|
+
relationship = self.relationships.find_by(follow_id: other_user.id)
|
31
|
+
relationship.destroy if relationship
|
32
|
+
end
|
33
|
+
|
34
|
+
def following?(other_user)
|
35
|
+
self.followings.include?(other_user)
|
36
|
+
end
|
37
|
+
```
|
2
コード修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
```
|
5
5
|
@user = User.find_by(current_user.id)
|
6
6
|
|
7
|
-
@
|
7
|
+
@follow_users = @user.followings
|
8
8
|
```
|
9
9
|
|
10
10
|
しかしこれだとエラーになるようで、
|
1
コード修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
```
|
5
5
|
@user = User.find_by(current_user.id)
|
6
6
|
|
7
|
-
@folow_users = @user.
|
7
|
+
@folow_users = @user.followings
|
8
8
|
```
|
9
9
|
|
10
10
|
しかしこれだとエラーになるようで、
|