質問編集履歴
1
情報訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,51 +10,43 @@
|
|
10
10
|
|
11
11
|
### いいねボタンを押した時の挙動
|
12
12
|
|
13
|
-
|
13
|
+
下記のエラーが出ている状況です。
|
14
14
|
|
15
15
|
### いいねボタンを押した時のログ
|
16
16
|
|
17
17
|
```ここに言語を入力
|
18
18
|
|
19
|
-
Started
|
19
|
+
Started POST "/likes" for ::1 at 2020-11-27 13:04:30 +0900
|
20
20
|
|
21
|
-
Processing by
|
21
|
+
Processing by LikesController#create as HTML
|
22
22
|
|
23
|
-
Parameters: {"co
|
23
|
+
Parameters: {"authenticity_token"=>"qf1hIs6n7xzMfSiQpK8iFA6tzLn56nzlsLWlkVEP8Ls19Eu9SPJWyNMSUcoBXRFhb2XJaBO42q6FjLi7cqrG3w=="}
|
24
24
|
|
25
|
-
|
25
|
+
User Load (1.1ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 4 ORDER BY `users`.`id` ASC LIMIT 1
|
26
26
|
|
27
|
-
↳ app/controllers/
|
27
|
+
↳ app/controllers/likes_controller.rb:3:in `create'
|
28
28
|
|
29
|
-
|
29
|
+
(0.2ms) BEGIN
|
30
30
|
|
31
|
-
|
31
|
+
↳ app/controllers/likes_controller.rb:3:in `create'
|
32
32
|
|
33
|
-
|
33
|
+
Like Exists? (0.4ms) SELECT 1 AS one FROM `likes` WHERE `likes`.`message_id` IS NULL AND `likes`.`user_id` = 4 LIMIT 1
|
34
34
|
|
35
|
-
|
35
|
+
↳ app/controllers/likes_controller.rb:3:in `create'
|
36
36
|
|
37
|
-
|
37
|
+
(0.4ms) ROLLBACK
|
38
38
|
|
39
|
-
|
39
|
+
↳ app/controllers/likes_controller.rb:3:in `create'
|
40
40
|
|
41
|
-
|
41
|
+
No template found for LikesController#create, rendering head :no_content
|
42
42
|
|
43
|
-
|
43
|
+
Completed 204 No Content in 12ms (ActiveRecord: 2.2ms | Allocations: 5543)
|
44
44
|
|
45
|
-
↳ app/models/user.rb:42:in `already_liked?'
|
46
45
|
|
47
|
-
User Load (0.7ms) SELECT `users`.* FROM `users` INNER JOIN `likes` ON `users`.`id` = `likes`.`user_id` WHERE `likes`.`message_id` = 18
|
48
46
|
|
49
|
-
↳ app/views/messages/show_message.html.erb:14
|
50
47
|
|
51
|
-
Rendered messages/show_message.html.erb within layouts/application (Duration: 10.8ms | Allocations: 4581)
|
52
48
|
|
53
|
-
[Webpacker] Everything's up-to-date. Nothing to do
|
54
49
|
|
55
|
-
Rendered layouts/_flash.scores.html.erb (Duration: 0.1ms | Allocations: 18)
|
56
|
-
|
57
|
-
Completed 200 OK in 24ms (Views: 16.9ms | ActiveRecord: 4.2ms | Allocations: 9323)
|
58
50
|
|
59
51
|
```
|
60
52
|
|
@@ -126,6 +118,42 @@
|
|
126
118
|
|
127
119
|
|
128
120
|
|
121
|
+
```ここに言語を入力
|
122
|
+
|
123
|
+
#likes_controller.rb
|
124
|
+
|
125
|
+
class LikesController < ApplicationController
|
126
|
+
|
127
|
+
def create
|
128
|
+
|
129
|
+
@like = current_user.likes.create(message_id: params[:message_id])
|
130
|
+
|
131
|
+
# redirect_to root_path
|
132
|
+
|
133
|
+
# redirect_back(fallback_location: root_path)
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
def destroy
|
140
|
+
|
141
|
+
@like = Like.find_by(message_id: params[:message_id], user_id: current_user.id)
|
142
|
+
|
143
|
+
@like.destroy
|
144
|
+
|
145
|
+
# redirect_to root_path
|
146
|
+
|
147
|
+
redirect_back(fallback_location: root_path)
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
```
|
154
|
+
|
155
|
+
|
156
|
+
|
129
157
|
```ruby
|
130
158
|
|
131
159
|
#routes.rb
|