質問編集履歴

3

追記

2020/01/06 08:48

投稿

is02
is02

スコア17

test CHANGED
File without changes
test CHANGED
@@ -280,6 +280,42 @@
280
280
 
281
281
  にしているためだと思われますが、indexのルートであるpost_images_pathと書いてもroutes errorが表示されてしまいます。
282
282
 
283
+ favorites_controller.rb(controller)
284
+
285
+ ```
286
+
287
+ class FavoritesController < ApplicationController
288
+
289
+ def create
290
+
291
+ post_image = PostImage.find(params[:post_image_id])
292
+
293
+ favorite = current_user.favorites.new(post_image_id: post_image.id)
294
+
295
+ favorite.save
296
+
297
+ redirect_to post_image_path(post_image)
298
+
299
+ end
300
+
301
+
302
+
303
+ def destroy
304
+
305
+ post_image = PostImage.find(params[:post_image_id])
306
+
307
+ favorite = current_user.favorites.find_by(post_image_id: post_image.id)
308
+
309
+ favorite.destroy
310
+
311
+ redirect_to post_image_path(post_image)
312
+
313
+ end
314
+
315
+ end
316
+
317
+ ```
318
+
283
319
 
284
320
 
285
321
  Rails 5.2.4.1

2

追記

2020/01/06 08:48

投稿

is02
is02

スコア17

test CHANGED
File without changes
test CHANGED
@@ -268,6 +268,20 @@
268
268
 
269
269
 
270
270
 
271
+ ### 追記
272
+
273
+ @post_imagesをpost_imageにしたら投稿一覧にいいねボタンが表示されるようになりました。
274
+
275
+
276
+
277
+ 新たなエラーとして、いいねを押すと詳細ページに飛んでしまいます。
278
+
279
+ **link_to post_image_favorites_path(@post_image)**
280
+
281
+ にしているためだと思われますが、indexのルートであるpost_images_pathと書いてもroutes errorが表示されてしまいます。
282
+
283
+
284
+
271
285
  Rails 5.2.4.1
272
286
 
273
287
  ruby 2.5.7p206 (2019-10-01 revision 67816) [x86_64-linux-gnu]

1

バージョン記載

2020/01/06 08:43

投稿

is02
is02

スコア17

test CHANGED
File without changes
test CHANGED
@@ -265,3 +265,9 @@
265
265
  定義されていないということは理解できるんですが、どう直せば表示されるのかがわかりません。
266
266
 
267
267
  ご教示いただけると幸いです。
268
+
269
+
270
+
271
+ Rails 5.2.4.1
272
+
273
+ ruby 2.5.7p206 (2019-10-01 revision 67816) [x86_64-linux-gnu]