質問編集履歴
3
指摘頂いたcontrollerの条件分岐を記述
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,11 +60,15 @@
|
|
60
60
|
|
61
61
|
if params[:all].present?
|
62
62
|
|
63
|
+
@score.destroy_all
|
64
|
+
|
65
|
+
else
|
66
|
+
|
63
|
-
@score.destroy
|
67
|
+
@score.destroy
|
68
|
+
|
69
|
+
end
|
64
70
|
|
65
71
|
redirect_to root_path
|
66
|
-
|
67
|
-
end
|
68
72
|
|
69
73
|
end
|
70
74
|
|
2
viewとcontrollerにご回答頂いた点を追記いたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -58,9 +58,13 @@
|
|
58
58
|
|
59
59
|
@score = Score.find(params[:id])
|
60
60
|
|
61
|
+
if params[:all].present?
|
62
|
+
|
61
63
|
@score.destroy
|
62
64
|
|
63
65
|
redirect_to root_path
|
66
|
+
|
67
|
+
end
|
64
68
|
|
65
69
|
end
|
66
70
|
|
@@ -110,9 +114,7 @@
|
|
110
114
|
|
111
115
|
<%= link_to "一番新しいスコアを削除", score_path(@scores.ids), method: :delete %>
|
112
116
|
|
113
|
-
<%= link_to "全てのスコアを削除", score_path(@scores.ids
|
117
|
+
<%= link_to "全てのスコアを削除", score_path(@scores.ids, all: true) %>
|
114
|
-
|
115
|
-
</div>
|
116
118
|
|
117
119
|
|
118
120
|
|
@@ -140,15 +142,31 @@
|
|
140
142
|
|
141
143
|
```
|
142
144
|
|
143
|
-
この記述は新しいスコアを1つ消す、となっています。
|
144
145
|
|
145
|
-
おそらく記述は比較的これに近いのではないかと推察します。
|
146
146
|
|
147
147
|
### 試したこと
|
148
148
|
|
149
149
|
|
150
150
|
|
151
|
+
ご回答頂いた通りcontrollerに
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
|
155
|
+
if params[:all].present?
|
156
|
+
|
157
|
+
```
|
158
|
+
|
159
|
+
で条件分岐いたしましたが
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
|
163
|
+
Unknown action
|
164
|
+
|
151
|
-
destro
|
165
|
+
The action 'show' could not be found for ScoresController
|
166
|
+
|
167
|
+
```
|
168
|
+
|
169
|
+
というエラーが出ました。
|
152
170
|
|
153
171
|
|
154
172
|
|
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,13 +8,119 @@
|
|
8
8
|
|
9
9
|
### 該当のソースコード
|
10
10
|
|
11
|
-
control
|
11
|
+
controler
|
12
12
|
|
13
13
|
```ruby
|
14
14
|
|
15
|
+
class ScoresController < ApplicationController
|
16
|
+
|
17
|
+
before_action :authenticate_user!
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
def index
|
24
|
+
|
25
|
+
@score = Score.new
|
26
|
+
|
27
|
+
@scores = current_user.scores.order("created_at DESC")
|
28
|
+
|
29
|
+
@chart = current_user.scores.pluck(:created_at, :score)
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
def create
|
36
|
+
|
37
|
+
@score = Score.new(scores_params)
|
38
|
+
|
39
|
+
if @score.save
|
40
|
+
|
41
|
+
redirect_to root_path
|
42
|
+
|
43
|
+
else
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
render :index
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
def destroy
|
58
|
+
|
59
|
+
@score = Score.find(params[:id])
|
60
|
+
|
61
|
+
@score.destroy
|
62
|
+
|
63
|
+
redirect_to root_path
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
def scores_params
|
74
|
+
|
75
|
+
params.require(:score).permit(:score).merge(user_id: current_user.id)
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
view
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
|
87
|
+
<%= form_with model: @score, class: 'form', local: true do |f| %>
|
88
|
+
|
89
|
+
<div class="form-input">
|
90
|
+
|
91
|
+
<%= f.number_field :score, step: "0.1", class: 'form-score', placeholder: 'type a score' %>
|
92
|
+
|
93
|
+
<%= f.submit '送信', class: 'form-submit' %>
|
94
|
+
|
95
|
+
</div>
|
96
|
+
|
97
|
+
<% end %>
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
<%= javascript_include_tag "//www.google.com/jsapi" %>
|
102
|
+
|
103
|
+
<%= line_chart @chart, points: false, series: false, curve: false, discrete: true, xtitle: "日付", ytitle: "スコア", width: "100%", height: "500px", decimal: ",", min: 400, max: 654 %>
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
<div class="sccore_destroy">
|
110
|
+
|
15
111
|
<%= link_to "一番新しいスコアを削除", score_path(@scores.ids), method: :delete %>
|
16
112
|
|
17
|
-
<%= link_to "全てのスコアを削除", score_path(@scores.ids)
|
113
|
+
<%= link_to "全てのスコアを削除", score_path(@scores.ids).all%>
|
114
|
+
|
115
|
+
</div>
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
<div id="score_b">
|
120
|
+
|
121
|
+
<%= render @scores%>
|
122
|
+
|
123
|
+
</div>
|
18
124
|
|
19
125
|
```
|
20
126
|
|