質問編集履歴
1
解決済みのため、画像とソースコードを削除しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,73 +3,3 @@
|
|
3
3
|
現在、railsを使ってツイッターのクローンアプリを作成しているのですが、ターミナル上でユーザーのフォロー、アンフォローの操作をしたいのですがうまくいかず困っています。
|
4
4
|
|
5
5
|
正直何が原因でエラーが出ているのか全くわからないため、お手数ですがご教示おねがいします。
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
userモデル
|
10
|
-
|
11
|
-
```class User < ApplicationRecord
|
12
|
-
|
13
|
-
before_save { self.email.downcase! }
|
14
|
-
|
15
|
-
validates :name, presence: true, length: { maximum: 50 }
|
16
|
-
|
17
|
-
validates :email, presence: true, length: { maximum: 255 },
|
18
|
-
|
19
|
-
format: { with: /\A[\w+\-.]+@[a-z\d\-.]+.[a-z]+\z/i },
|
20
|
-
|
21
|
-
uniqueness: { case_sensitive: false }
|
22
|
-
|
23
|
-
has_secure_password
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
has_many :microposts
|
28
|
-
|
29
|
-
has_many :relationships
|
30
|
-
|
31
|
-
has_many :followings, through: :relationships, source: :follow
|
32
|
-
|
33
|
-
has_many :reverses_of_relationship, class_name: 'Relationship', foreign_key: 'follow_id'
|
34
|
-
|
35
|
-
has_many :followers, through: :reverses_of_relationship, source: :user
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
def follow(other_user)
|
40
|
-
|
41
|
-
unless self == other_user
|
42
|
-
|
43
|
-
self.relationships.find_or_create_by(follow_id: other_user.id)
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
def unfollow(other_user)
|
52
|
-
|
53
|
-
relationship = self.relationships.find_by(follow_id: other_user.id)
|
54
|
-
|
55
|
-
relationship.destroy if relationship
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
def following?(other_user)
|
62
|
-
|
63
|
-
self.followings.include?(other_user)
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
```
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
![cloud9にて出ているエラー](e673c8b65d804cea28c6fd6027c9bb4e.png)
|