質問編集履歴

2

エラーメッセージの追加

2021/01/10 04:31

投稿

spring_dexcter
spring_dexcter

スコア13

test CHANGED
File without changes
test CHANGED
@@ -6,11 +6,31 @@
6
6
 
7
7
  ```
8
8
 
9
- app/models/talk.rb:16:in `like?'
9
+ Started GET "/talks" at 2021-01-10 13:28:32 +0900
10
+
11
+ Processing by TalksController#index as HTML
12
+
13
+ Rendering talks/index.html.slim within layouts/application
14
+
15
+ Talk Load (5.9ms) SELECT "talks".* FROM "talks" ORDER BY "talks"."created_at" DESC
16
+
17
+ ↳ app/views/talks/index.html.slim:9
18
+
19
+ User Load (3.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
20
+
21
+ ↳ app/views/talks/index.html.slim:13
22
+
23
+ User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
24
+
25
+ ↳ app/helpers/sessions_helper.rb:20:in `current_user'
26
+
27
+ User Exists? (4.6ms) SELECT 1 AS one FROM "users" INNER JOIN "likes" ON "users"."id" = "likes"."user_id" WHERE "likes"."talk_id" = $1 AND "users"."id" = $2 LIMIT $3 [["talk_id", 17], ["id", 1], ["LIMIT", 1]]
28
+
29
+ ↳ app/models/talk.rb:16:in `like?'
10
30
 
11
31
  Rendered talks/index.html.slim within layouts/application
12
32
 
13
- Completed 500 Internal Server Error in 36ms
33
+ Completed 500 Internal Server Error in 69ms
14
34
 
15
35
  ```
16
36
 

1

modelコードの追加

2021/01/10 04:31

投稿

spring_dexcter
spring_dexcter

スコア13

test CHANGED
File without changes
test CHANGED
@@ -149,3 +149,37 @@
149
149
 
150
150
 
151
151
  ```
152
+
153
+ talk.rb
154
+
155
+ ```
156
+
157
+ belongs_to :user
158
+
159
+ has_many :likes, dependent: :destroy
160
+
161
+ has_many :liked_users, through: :likes, source: :user
162
+
163
+ validates :user_id, presence: true
164
+
165
+ validates :content, presence: true
166
+
167
+ acts_as_taggable
168
+
169
+
170
+
171
+ scope :recent, -> { order(created_at: "DESC") }
172
+
173
+
174
+
175
+
176
+
177
+ def like?(user)
178
+
179
+ liked_users.include?(user)
180
+
181
+ end
182
+
183
+
184
+
185
+ ```