質問編集履歴
2
Controllerを全部記載しました(余計なendを消してSyntax errorは解消)!
title
CHANGED
File without changes
|
body
CHANGED
@@ -21,15 +21,83 @@
|
|
21
21
|
しかし、「Syntax error」と出ており、何をどう直すべきか分からないため、ご意見・アドバイスを頂戴できますと幸いです。
|
22
22
|
|
23
23
|
```RecordsController
|
24
|
+
class RecordsController < ApplicationController
|
25
|
+
before_action :authenticate_user!
|
24
26
|
|
25
27
|
def index
|
26
28
|
@records = current_user.records.includes(:practices).page(params[:page]).per(8)
|
27
|
-
|
28
29
|
total_practice_time = Record.includes(:practices)
|
29
30
|
total_practice_time.each do |total|
|
30
31
|
total.sum(:practice_time)
|
31
32
|
end
|
33
|
+
@q = Record.ransack(params[:q])
|
34
|
+
@search_records = @q.result(distinct: true)
|
35
|
+
end
|
36
|
+
|
37
|
+
def show
|
38
|
+
@record = Record.find(params[:id])
|
39
|
+
end
|
40
|
+
|
41
|
+
def new
|
42
|
+
@record = Record.new
|
43
|
+
output = @record.outputs.build
|
44
|
+
practice = @record.practices.build
|
45
|
+
task = @record.tasks.build
|
46
|
+
end
|
47
|
+
|
48
|
+
def create
|
49
|
+
@record = Record.new(record_params)
|
50
|
+
logger.info "###### #{@record.inspect}"
|
51
|
+
if @record.save
|
52
|
+
flash[:success] = "練習内容の登録が完了しました。"
|
53
|
+
redirect_to records_url
|
54
|
+
else
|
55
|
+
flash[:alert] = "登録に失敗しました。"
|
56
|
+
render :new
|
32
57
|
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def edit
|
61
|
+
@record = Record.find_by(id: params[:id])
|
62
|
+
end
|
63
|
+
|
64
|
+
def update
|
65
|
+
@record = Record.find_by(id: params[:id])
|
66
|
+
if @record.update(record_params)
|
67
|
+
flash[:success] = "練習内容の更新が完了しました。"
|
68
|
+
redirect_to records_url
|
69
|
+
else
|
70
|
+
flash[:alert] = "更新に失敗しました。"
|
71
|
+
render :edit
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def destroy
|
76
|
+
record = Record.find_by(id:params[:id])
|
77
|
+
record.destroy
|
78
|
+
|
79
|
+
redirect_to root_path, notice: "練習記録を削除しました。"
|
80
|
+
end
|
81
|
+
|
82
|
+
def aggregate_result
|
83
|
+
@record = Record.find(params[:id])
|
84
|
+
gon.data = Record.where(params[:practice_time])
|
85
|
+
6.times do
|
86
|
+
# gon.data << rand(100.0)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def set_user
|
93
|
+
@user = current_user || User.new
|
94
|
+
end
|
95
|
+
|
96
|
+
def record_params
|
97
|
+
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)
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
33
101
|
```
|
34
102
|
|
35
103
|
```slim
|
@@ -108,9 +176,48 @@
|
|
108
176
|
```
|
109
177
|
|
110
178
|
#エラーメッセージと画像
|
111
|
-
再開したところ、Syntaxerrorでした。
|
179
|
+
~~再開したところ、Syntaxerrorでした。
|
180
|
+
~~
|
181
|
+
→indexアクションに、1つ余分にendが入っていたことに気づいたので修正しました。すると、下記のログと画像を確認しました。
|
112
182
|
|
183
|
+
sumメソッドが提示されていませんと怒られています。。。
|
184
|
+
|
113
185
|
```log
|
186
|
+
Started POST "/__better_errors/c4bbb4c567585e78/variables" for ::1 at 2020-06-16 22:19:03 +0900
|
187
|
+
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
|
188
|
+
Processing by RecordsController#index as HTML
|
189
|
+
Parameters: {"utf8"=>"✓", "q"=>{"training_date_eq"=>""}, "commit"=>"練習日で検索"}
|
190
|
+
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 3], ["LIMIT", 1]]
|
191
|
+
↳ /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
|
192
|
+
Record Load (0.3ms) SELECT "records".* FROM "records"
|
193
|
+
↳ app/controllers/records_controller.rb:7
|
194
|
+
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]]
|
195
|
+
↳ app/controllers/records_controller.rb:7
|
196
|
+
Completed 500 Internal Server Error in 38ms (ActiveRecord: 9.7ms)
|
197
|
+
|
198
|
+
|
199
|
+
|
200
|
+
NoMethodError - undefined method `sum' for #<Record:0x00007ffaf6c1acc0>:
|
201
|
+
app/controllers/records_controller.rb:8:in `block in index'
|
202
|
+
app/controllers/records_controller.rb:7:in `index'
|
203
|
+
|
204
|
+
Started POST "/__better_errors/28783482a38955a1/variables" for ::1 at 2020-06-16 22:19:04 +0900
|
205
|
+
Record Load (0.3ms) SELECT "records".* FROM "records" WHERE "records"."user_id" = $1 LIMIT $2 OFFSET $3 [["user_id", "3"], ["LIMIT", 8], ["OFFSET", 0]]
|
206
|
+
↳ /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
|
207
|
+
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]]
|
208
|
+
↳ /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
|
209
|
+
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]]
|
210
|
+
↳ /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
|
211
|
+
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]]
|
212
|
+
↳ /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
|
213
|
+
|
214
|
+
```
|
215
|
+
|
216
|
+

|
217
|
+
|
218
|
+
|
219
|
+
##最初に質問していた時のエラーメッセージと画像
|
220
|
+
```log
|
114
221
|
Started GET "/" for ::1 at 2020-06-16 21:56:55 +0900
|
115
222
|
|
116
223
|
SyntaxError - syntax error, unexpected end, expecting end-of-input:
|
1
エラーメッセージと画像を添付いたしました。ご確認頂けますと幸いです。
title
CHANGED
File without changes
|
body
CHANGED
@@ -105,4 +105,24 @@
|
|
105
105
|
t.datetime "updated_at", null: false
|
106
106
|
t.index ["record_id"], name: "index_practices_on_record_id"
|
107
107
|
end
|
108
|
-
```
|
108
|
+
```
|
109
|
+
|
110
|
+
#エラーメッセージと画像
|
111
|
+
再開したところ、Syntaxerrorでした。
|
112
|
+
|
113
|
+
```log
|
114
|
+
Started GET "/" for ::1 at 2020-06-16 21:56:55 +0900
|
115
|
+
|
116
|
+
SyntaxError - syntax error, unexpected end, expecting end-of-input:
|
117
|
+
app/controllers/records_controller.rb:80:in `'
|
118
|
+
|
119
|
+
Started POST "/__better_errors/cbfc53cbe6b50718/variables" for ::1 at 2020-06-16 21:56:56 +0900
|
120
|
+
Started GET "/" for ::1 at 2020-06-16 21:56:57 +0900
|
121
|
+
|
122
|
+
SyntaxError - syntax error, unexpected end, expecting end-of-input:
|
123
|
+
app/controllers/records_controller.rb:80:in `'
|
124
|
+
|
125
|
+
Started POST "/__better_errors/66effe8f5f8cef8c/variables" for ::1 at 2020-06-16 21:56:57 +0900
|
126
|
+
```
|
127
|
+
|
128
|
+

|