質問編集履歴

1

routesなど載せられていなかったので修正しました。

2021/12/24 10:40

投稿

rororo11
rororo11

スコア1

test CHANGED
File without changes
test CHANGED
@@ -18,6 +18,12 @@
18
18
 
19
19
  Logには以下のようなメッセージが表示されました。
20
20
 
21
+ 「undefined method `favorited_by?' 」とありますが、book.rbに定義しているので
22
+
23
+ 原因がわかりません。
24
+
25
+
26
+
21
27
  ```
22
28
 
23
29
  Started DELETE "/books/1/favorites" for 211.120.130.120 at 2021-12-24 06:11:36 +0000
@@ -94,7 +100,9 @@
94
100
 
95
101
 
96
102
 
103
+ views/favorites/create.js.erb
104
+
97
- create.js.erb/delete.js.erb
105
+ views/favorites/delete.js.erb
98
106
 
99
107
  ```ここに言語を入力
100
108
 
@@ -138,7 +146,7 @@
138
146
 
139
147
 
140
148
 
141
- favorites/_favorite.html.erb
149
+ views/favorites/_favorite.html.erb
142
150
 
143
151
  ```
144
152
 
@@ -164,7 +172,7 @@
164
172
 
165
173
 
166
174
 
167
- show.html.erb
175
+ views/books/show.html.erb
168
176
 
169
177
  ```ここに言語を入力
170
178
 
@@ -178,7 +186,7 @@
178
186
 
179
187
 
180
188
 
181
- _index.html.erb
189
+ views/books/_index.html.erb
182
190
 
183
191
  ```ここに言語を入力
184
192
 
@@ -224,6 +232,82 @@
224
232
 
225
233
 
226
234
 
235
+ models/book.rb
236
+
237
+ ```ここに言語を入力
238
+
239
+ class Book < ApplicationRecord
240
+
241
+ belongs_to :user
242
+
243
+ has_many :favorites, dependent: :destroy
244
+
245
+ has_many :book_comments, dependent: :destroy
246
+
247
+
248
+
249
+ def favorited_by?(user)
250
+
251
+ favorites.where(user_id: user.id).exists?
252
+
253
+ end
254
+
255
+
256
+
257
+ validates :title, presence: true
258
+
259
+ validates :body, presence: true, length: {maximum: 200}
260
+
261
+ end
262
+
263
+ ```
264
+
265
+ routes
266
+
267
+ ```ここに言語を入力
268
+
269
+ Rails.application.routes.draw do
270
+
271
+ get 'search/search'
272
+
273
+ devise_for :users
274
+
275
+ root 'homes#top'
276
+
277
+ get 'home/about' => 'homes#about'
278
+
279
+ get "users/show" => "users#show"
280
+
281
+ get '/users' => "users#index"
282
+
283
+ get "users/:id" => "users#show", as: :mypage
284
+
285
+ get 'search' => "search#search"
286
+
287
+ resources :users,only: [:show,:index,:edit,:update] do
288
+
289
+ resources :relationships, only: [:create, :destroy]
290
+
291
+ get :followings, on: :member
292
+
293
+ get :followers, on: :member
294
+
295
+ end
296
+
297
+ resources :books do
298
+
299
+ resource :favorites, only: [:create, :destroy]
300
+
301
+ resources :book_comments, only: [:create, :destroy]
302
+
303
+ end
304
+
305
+ end
306
+
307
+ ```
308
+
309
+
310
+
227
311
  application.js
228
312
 
229
313
  ```ここに言語を入力
@@ -289,3 +373,7 @@
289
373
 
290
374
 
291
375
  ここにより詳細な情報を記載してください。
376
+
377
+
378
+
379
+ どうぞ宜しくお願い致します。