質問編集履歴
2
Controllerを全部記載しました(余計なendを消してSyntax errorは解消)!
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,14 +44,16 @@
|
|
44
44
|
|
45
45
|
```RecordsController
|
46
46
|
|
47
|
+
class RecordsController < ApplicationController
|
48
|
+
|
49
|
+
before_action :authenticate_user!
|
50
|
+
|
47
51
|
|
48
52
|
|
49
53
|
def index
|
50
54
|
|
51
55
|
@records = current_user.records.includes(:practices).page(params[:page]).per(8)
|
52
56
|
|
53
|
-
|
54
|
-
|
55
57
|
total_practice_time = Record.includes(:practices)
|
56
58
|
|
57
59
|
total_practice_time.each do |total|
|
@@ -60,8 +62,142 @@
|
|
60
62
|
|
61
63
|
end
|
62
64
|
|
65
|
+
@q = Record.ransack(params[:q])
|
66
|
+
|
67
|
+
@search_records = @q.result(distinct: true)
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
def show
|
74
|
+
|
75
|
+
@record = Record.find(params[:id])
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
def new
|
82
|
+
|
83
|
+
@record = Record.new
|
84
|
+
|
85
|
+
output = @record.outputs.build
|
86
|
+
|
87
|
+
practice = @record.practices.build
|
88
|
+
|
89
|
+
task = @record.tasks.build
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
def create
|
96
|
+
|
97
|
+
@record = Record.new(record_params)
|
98
|
+
|
99
|
+
logger.info "###### #{@record.inspect}"
|
100
|
+
|
101
|
+
if @record.save
|
102
|
+
|
103
|
+
flash[:success] = "練習内容の登録が完了しました。"
|
104
|
+
|
105
|
+
redirect_to records_url
|
106
|
+
|
107
|
+
else
|
108
|
+
|
109
|
+
flash[:alert] = "登録に失敗しました。"
|
110
|
+
|
111
|
+
render :new
|
112
|
+
|
63
113
|
end
|
64
114
|
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
def edit
|
120
|
+
|
121
|
+
@record = Record.find_by(id: params[:id])
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
def update
|
128
|
+
|
129
|
+
@record = Record.find_by(id: params[:id])
|
130
|
+
|
131
|
+
if @record.update(record_params)
|
132
|
+
|
133
|
+
flash[:success] = "練習内容の更新が完了しました。"
|
134
|
+
|
135
|
+
redirect_to records_url
|
136
|
+
|
137
|
+
else
|
138
|
+
|
139
|
+
flash[:alert] = "更新に失敗しました。"
|
140
|
+
|
141
|
+
render :edit
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
def destroy
|
150
|
+
|
151
|
+
record = Record.find_by(id:params[:id])
|
152
|
+
|
153
|
+
record.destroy
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
redirect_to root_path, notice: "練習記録を削除しました。"
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
def aggregate_result
|
164
|
+
|
165
|
+
@record = Record.find(params[:id])
|
166
|
+
|
167
|
+
gon.data = Record.where(params[:practice_time])
|
168
|
+
|
169
|
+
6.times do
|
170
|
+
|
171
|
+
# gon.data << rand(100.0)
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
private
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
def set_user
|
184
|
+
|
185
|
+
@user = current_user || User.new
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
def record_params
|
192
|
+
|
193
|
+
params.require(:record).permit(:record_id, :training_date, :learning_point, outputs_attributes:[:output_name, :id], practices_attributes:[:practice_item, :practice_time, :id], tasks_attributes:[:task_name, :id]).merge(user_id: current_user.id)
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
end
|
200
|
+
|
65
201
|
```
|
66
202
|
|
67
203
|
|
@@ -218,12 +354,90 @@
|
|
218
354
|
|
219
355
|
#エラーメッセージと画像
|
220
356
|
|
221
|
-
再開したところ、Syntaxerrorでした。
|
357
|
+
~~再開したところ、Syntaxerrorでした。
|
358
|
+
|
359
|
+
~~
|
360
|
+
|
361
|
+
→indexアクションに、1つ余分にendが入っていたことに気づいたので修正しました。すると、下記のログと画像を確認しました。
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
sumメソッドが提示されていませんと怒られています。。。
|
222
366
|
|
223
367
|
|
224
368
|
|
225
369
|
```log
|
226
370
|
|
371
|
+
Started POST "/__better_errors/c4bbb4c567585e78/variables" for ::1 at 2020-06-16 22:19:03 +0900
|
372
|
+
|
373
|
+
Started GET "/records?utf8=%E2%9C%93&q%5Btraining_date_eq%5D=&commit=%E7%B7%B4%E7%BF%92%E6%97%A5%E3%81%A7%E6%A4%9C%E7%B4%A2" for ::1 at 2020-06-16 22:19:04 +0900
|
374
|
+
|
375
|
+
Processing by RecordsController#index as HTML
|
376
|
+
|
377
|
+
Parameters: {"utf8"=>"✓", "q"=>{"training_date_eq"=>""}, "commit"=>"練習日で検索"}
|
378
|
+
|
379
|
+
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 3], ["LIMIT", 1]]
|
380
|
+
|
381
|
+
↳ /Users/user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-5.2.4.3/lib/active_record/log_subscriber.rb:98
|
382
|
+
|
383
|
+
Record Load (0.3ms) SELECT "records".* FROM "records"
|
384
|
+
|
385
|
+
↳ app/controllers/records_controller.rb:7
|
386
|
+
|
387
|
+
Practice Load (0.5ms) SELECT "practices".* FROM "practices" WHERE "practices"."record_id" IN ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, $41) [["record_id", 1], ["record_id", 2], ["record_id", 3], ["record_id", 4], ["record_id", 5], ["record_id", 6], ["record_id", 7], ["record_id", 8], ["record_id", 9], ["record_id", 10], ["record_id", 11], ["record_id", 12], ["record_id", 13], ["record_id", 14], ["record_id", 15], ["record_id", 16], ["record_id", 17], ["record_id", 18], ["record_id", 19], ["record_id", 23], ["record_id", 24], ["record_id", 25], ["record_id", 26], ["record_id", 27], ["record_id", 28], ["record_id", 29], ["record_id", 30], ["record_id", 31], ["record_id", 32], ["record_id", 33], ["record_id", 34], ["record_id", 35], ["record_id", 36], ["record_id", 37], ["record_id", 38], ["record_id", 39], ["record_id", 40], ["record_id", 41], ["record_id", 62], ["record_id", 63], ["record_id", 64]]
|
388
|
+
|
389
|
+
↳ app/controllers/records_controller.rb:7
|
390
|
+
|
391
|
+
Completed 500 Internal Server Error in 38ms (ActiveRecord: 9.7ms)
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
NoMethodError - undefined method `sum' for #<Record:0x00007ffaf6c1acc0>:
|
400
|
+
|
401
|
+
app/controllers/records_controller.rb:8:in `block in index'
|
402
|
+
|
403
|
+
app/controllers/records_controller.rb:7:in `index'
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
Started POST "/__better_errors/28783482a38955a1/variables" for ::1 at 2020-06-16 22:19:04 +0900
|
408
|
+
|
409
|
+
Record Load (0.3ms) SELECT "records".* FROM "records" WHERE "records"."user_id" = $1 LIMIT $2 OFFSET $3 [["user_id", "3"], ["LIMIT", 8], ["OFFSET", 0]]
|
410
|
+
|
411
|
+
↳ /Users/user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-5.2.4.3/lib/active_record/log_subscriber.rb:98
|
412
|
+
|
413
|
+
Practice Load (1.2ms) SELECT "practices".* FROM "practices" WHERE "practices"."record_id" IN ($1, $2, $3) [["record_id", 62], ["record_id", 63], ["record_id", 64]]
|
414
|
+
|
415
|
+
↳ /Users/user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-5.2.4.3/lib/active_record/log_subscriber.rb:98
|
416
|
+
|
417
|
+
CACHE Record Load (0.0ms) SELECT "records".* FROM "records" WHERE "records"."user_id" = $1 LIMIT $2 OFFSET $3 [["user_id", "3"], ["LIMIT", 8], ["OFFSET", 0]]
|
418
|
+
|
419
|
+
↳ /Users/user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-5.2.4.3/lib/active_record/log_subscriber.rb:98
|
420
|
+
|
421
|
+
CACHE Practice Load (0.0ms) SELECT "practices".* FROM "practices" WHERE "practices"."record_id" IN ($1, $2, $3) [["record_id", 62], ["record_id", 63], ["record_id", 64]]
|
422
|
+
|
423
|
+
↳ /Users/user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-5.2.4.3/lib/active_record/log_subscriber.rb:98
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
```
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
![イメージ説明](2a5c393a6372b93e7743e50180e93be6.png)
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
##最初に質問していた時のエラーメッセージと画像
|
438
|
+
|
439
|
+
```log
|
440
|
+
|
227
441
|
Started GET "/" for ::1 at 2020-06-16 21:56:55 +0900
|
228
442
|
|
229
443
|
|
1
エラーメッセージと画像を添付いたしました。ご確認頂けますと幸いです。
test
CHANGED
File without changes
|
test
CHANGED
@@ -213,3 +213,43 @@
|
|
213
213
|
end
|
214
214
|
|
215
215
|
```
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
#エラーメッセージと画像
|
220
|
+
|
221
|
+
再開したところ、Syntaxerrorでした。
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
```log
|
226
|
+
|
227
|
+
Started GET "/" for ::1 at 2020-06-16 21:56:55 +0900
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
SyntaxError - syntax error, unexpected end, expecting end-of-input:
|
232
|
+
|
233
|
+
app/controllers/records_controller.rb:80:in `'
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
Started POST "/__better_errors/cbfc53cbe6b50718/variables" for ::1 at 2020-06-16 21:56:56 +0900
|
238
|
+
|
239
|
+
Started GET "/" for ::1 at 2020-06-16 21:56:57 +0900
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
SyntaxError - syntax error, unexpected end, expecting end-of-input:
|
244
|
+
|
245
|
+
app/controllers/records_controller.rb:80:in `'
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
Started POST "/__better_errors/66effe8f5f8cef8c/variables" for ::1 at 2020-06-16 21:56:57 +0900
|
250
|
+
|
251
|
+
```
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
![イメージ説明](ecd8c16914c475e6a0a4eb29b501afeb.png)
|