質問編集履歴
2
解決方法の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,6 +12,104 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
+
### おかげさまで解決しました(該当部分のみ)
|
16
|
+
|
17
|
+
resourcesからresourceに変更
|
18
|
+
|
19
|
+
```routes
|
20
|
+
|
21
|
+
resources :games, only: [:index, :show, :create, :destroy] do
|
22
|
+
|
23
|
+
resource :wants, only: [:create, :destroy]
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
```
|
28
|
+
|
29
|
+
すると↓が「game_want_pathじゃなくてgame_wants_pathじゃない?」というエラーが出たので、wantsにしたところ、エラーは出なくなりました
|
30
|
+
|
31
|
+
パーシャル化したファイル(app/views/wants/_want.html.erb)
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
<% if current_user.already_wanted?(@game) %>
|
36
|
+
|
37
|
+
<%= button_to 'いいねを取り消す', game_want_path(@game), method: :delete %>
|
38
|
+
|
39
|
+
<% else %>
|
40
|
+
|
41
|
+
<%= button_to 'いいね', game_wants_path(@game) %>
|
42
|
+
|
43
|
+
<% end %>
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
ですが、一つのゲームがループして出力されるごとにすべてのゲームのいいねボタンがでるようになってしまいましたので
|
50
|
+
|
51
|
+
以下のようにかきかえました
|
52
|
+
|
53
|
+
エラーが出るゲーム一覧ページ(app/views/games/index.html.erb)
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
<% if @games.any? %>
|
58
|
+
|
59
|
+
<ul class="list-unstyled">
|
60
|
+
|
61
|
+
<% @games.each do |game| %>
|
62
|
+
|
63
|
+
<li class="media">
|
64
|
+
|
65
|
+
<div class="media-body">
|
66
|
+
|
67
|
+
<div>
|
68
|
+
|
69
|
+
<%= link_to game_path(game) do %>
|
70
|
+
|
71
|
+
<%= image_tag game.image.to_s %>
|
72
|
+
|
73
|
+
<%= game.game_name %></p>
|
74
|
+
|
75
|
+
<% end %>
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<% @game = game %>
|
80
|
+
|
81
|
+
<div><%= render partial: 'wants/want' ,games: @games %></div>
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
</div>
|
86
|
+
|
87
|
+
</div>
|
88
|
+
|
89
|
+
</li>
|
90
|
+
|
91
|
+
<% end %>
|
92
|
+
|
93
|
+
</ul>
|
94
|
+
|
95
|
+
<% end %>
|
96
|
+
|
97
|
+
```
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
これで動くようになりました
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
15
113
|
### 発生している問題・エラーメッセージ
|
16
114
|
|
17
115
|
|
1
index.html.erb追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -440,13 +440,63 @@
|
|
440
440
|
|
441
441
|
|
442
442
|
|
443
|
-
|
443
|
+
ご指摘をいただいて編集したところ(app/views/games/index.html.erb)
|
444
|
+
|
444
|
-
|
445
|
+
```
|
446
|
+
|
445
|
-
|
447
|
+
<% if @games.any? %>
|
448
|
+
|
446
|
-
|
449
|
+
<ul class="list-unstyled">
|
450
|
+
|
447
|
-
|
451
|
+
<% @games.each do |game| %>
|
452
|
+
|
448
|
-
|
453
|
+
<li class="media">
|
454
|
+
|
449
|
-
|
455
|
+
<div class="media-body">
|
456
|
+
|
457
|
+
<div>
|
458
|
+
|
459
|
+
<%= link_to game_path(game) do %>
|
460
|
+
|
461
|
+
<%= image_tag game.image.to_s %>
|
462
|
+
|
463
|
+
<%= game.game_name %></p>
|
464
|
+
|
465
|
+
<% end %>
|
466
|
+
|
467
|
+
<% @games.each do |game| %>
|
468
|
+
|
469
|
+
<% @game = game %>
|
470
|
+
|
471
|
+
<div><%= render partial: 'wants/want' ,games: @games %></div>
|
472
|
+
|
473
|
+
<% end %>
|
474
|
+
|
475
|
+
</div>
|
476
|
+
|
477
|
+
</div>
|
478
|
+
|
479
|
+
</li>
|
480
|
+
|
481
|
+
<% end %>
|
482
|
+
|
483
|
+
</ul>
|
484
|
+
|
485
|
+
<% end %>
|
486
|
+
|
487
|
+
```
|
488
|
+
|
489
|
+
もしかしてroutes.rbのここが悪いのでは?と思ったところ
|
490
|
+
|
491
|
+
```
|
492
|
+
|
493
|
+
resources :games, only: [:index, :show, :create, :destroy] do
|
494
|
+
|
495
|
+
resources :wants, only: [:create, :destroy]
|
496
|
+
|
497
|
+
end
|
498
|
+
|
499
|
+
```
|
450
500
|
|
451
501
|
|
452
502
|
|