質問編集履歴
2
routesの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -296,6 +296,30 @@
|
|
296
296
|
|
297
297
|
```
|
298
298
|
|
299
|
+
###routes.rb
|
300
|
+
|
301
|
+
```
|
302
|
+
|
303
|
+
Rails.application.routes.draw do
|
304
|
+
|
305
|
+
devise_for :users
|
306
|
+
|
307
|
+
root to: "ideas#index"
|
308
|
+
|
309
|
+
resources :ideas do
|
310
|
+
|
311
|
+
resources :likes, only: [:create, :destroy]
|
312
|
+
|
313
|
+
resources :comments, only: :create
|
314
|
+
|
315
|
+
end
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
end
|
320
|
+
|
321
|
+
```
|
322
|
+
|
299
323
|
|
300
324
|
|
301
325
|
|
1
_link.html.erbの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,6 +34,34 @@
|
|
34
34
|
|
35
35
|
### 該当のソースコード
|
36
36
|
|
37
|
+
### shared/_like.html.erb
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
<% if Like.find_by(user_id: current_user.id, idea_id: @idea.id) %>
|
42
|
+
|
43
|
+
<%= link_to (idea_like_path(@idea.id)), method: :delete, id: "like-button", remote: true do %>
|
44
|
+
|
45
|
+
<span class="fa fa-heart like-btn-unlike"></span>
|
46
|
+
|
47
|
+
<%= @likes_count %>
|
48
|
+
|
49
|
+
<% end %>
|
50
|
+
|
51
|
+
<% else %>
|
52
|
+
|
53
|
+
<%= link_to (idea_likes_path(@idea.id)), method: :post, id: "like-button", remote: true do %>
|
54
|
+
|
55
|
+
<span class="fa fa-heart like-btn"></span>
|
56
|
+
|
57
|
+
<%= @likes_count %>
|
58
|
+
|
59
|
+
<% end %>
|
60
|
+
|
61
|
+
<% end %>
|
62
|
+
|
63
|
+
```
|
64
|
+
|
37
65
|
### like_controller.rb
|
38
66
|
|
39
67
|
```
|