質問編集履歴

1

問題のメソッドを追加

2022/03/30 05:28

投稿

sgs
sgs

スコア0

test CHANGED
File without changes
test CHANGED
@@ -62,6 +62,29 @@
62
62
  end
63
63
  end
64
64
  ```
65
+ **app/models/user.rb**
66
+ ```rb
67
+ .
68
+ .
69
+ .
70
+ # いいねする
71
+ def like(other_micropost)
72
+ likes << other_micropost
73
+ end
74
+
75
+ # いいね解除
76
+ def unlike(other_micropost)
77
+ favorites.find_by(micropost_id: other_micropost.id).destroy
78
+ end
79
+
80
+ # いいねしているか?
81
+ def like?(other_micropost)
82
+ likes.include?(other_micropost)
83
+ end
84
+ .
85
+ .
86
+ .
87
+ ```
65
88
  **app/views/favorites/create.js.erb**
66
89
  ```js
67
90
  $("#like_form").html("<%= escape_javascript(render(partial: 'favorites/unlike', locals: { micropost: @micropost })) %>");