質問編集履歴

1

サーバーログを追記

2021/07/24 02:05

投稿

Shuno
Shuno

スコア5

test CHANGED
File without changes
test CHANGED
@@ -36,19 +36,19 @@
36
36
 
37
37
  get reservations_path(user_id: other_user.id, from_user_id: user.id)
38
38
 
39
- get new_reservation_path(user_id: other_user.id), params: { day: "2021-07-24",
39
+ get new_reservation_path(user_id: other_user.id), params: { day: "2021-07-25",
40
-
40
+
41
- time: "9:00",
41
+ time: "10:00",
42
42
 
43
43
  user_id: other_user.id }
44
44
 
45
45
  expect {
46
46
 
47
- post "/reservations", params: { reservation: { day: "2021-07-24",
47
+ post "/reservations", params: { reservation: { day: "2021-07-25",
48
-
48
+
49
- time: "9:00",
49
+ time: "10:00",
50
-
50
+
51
- start_time: "2021-07-24T09:00:00+09:00",
51
+ start_time: "2021-07-25T10:00:00+09:00",
52
52
 
53
53
  user_id: other_user.id } }
54
54
 
@@ -108,49 +108,95 @@
108
108
 
109
109
  ### 該当のソースコード
110
110
 
111
- app/models/reservation.rb
111
+ app/controllers/reservations_controller.rb
112
-
112
+
113
- ```
113
+ ```
114
-
114
+
115
- class Reservation < ApplicationRecord
115
+ class ReservationsController < ApplicationController
116
-
117
- belongs_to :user
116
+
118
-
119
- validates :user_id, presence: true
120
-
121
- validates :from_user_id, presence: true
122
-
123
- validates :day, presence: true
124
-
125
- validates :time, presence: true
126
-
127
- validates :start_time, presence: true, uniqueness: true
128
-
129
-
130
-
131
- def self.reservations_after_one_month
117
+ before_action :logged_in_user
118
+
119
+
120
+
132
-
121
+ def index
122
+
133
- # 今日から1ヶ月先までのデータを取得
123
+ @user = User.find(params[:user_id])
134
-
124
+
135
- reservations = Reservation.all.where("day >= ?", Date.current).where("day < ?", Date.current >> 1).order(day: :desc)
125
+ @reservations = Reservation.where("day >= ?", Date.current).where("day < ?", Date.current >> 3).order(day: :desc).where("user_id = ? or from_user_id = ?", @user.id, current_user.id)
126
+
136
-
127
+ end
128
+
129
+
130
+
137
- # 配列を作成し、データを格納
131
+ def new
138
-
139
- # DBアクセスを減らすために必要なデータを配列にデータを入れる
132
+
140
-
141
- reservation_data = []
133
+ @user = User.find(params[:user_id])
142
-
134
+
143
- reservations.each do |reservation|
135
+ @reservation = Reservation.new
144
-
136
+
145
- reservations_hash = {}
137
+ @day = params[:day]
138
+
146
-
139
+ @time = params[:time]
140
+
147
- reservations_hash.merge!(day: reservation.day.strftime("%Y-%m-%d"), time: reservation.time)
141
+ @start_time = DateTime.parse(@day + " " + @time + " " + "JST")
142
+
148
-
143
+ end
144
+
145
+
146
+
147
+ def show
148
+
149
+ @reservation = Reservation.find(params[:id])
150
+
151
+ end
152
+
153
+
154
+
155
+ def create
156
+
149
- reservation_data.push(reservations_hash)
157
+ @reservation = Reservation.new(reservation_params)
158
+
159
+ if @reservation.save
160
+
161
+ flash[:success] = "ビデオ通話予約しました"
162
+
163
+ redirect_to reservation_path @reservation.id
164
+
165
+ else
166
+
167
+ render :new
150
168
 
151
169
  end
152
170
 
171
+ end
172
+
173
+
174
+
175
+ def destroy
176
+
177
+ @reservation = Reservation.find(params[:id])
178
+
179
+ if @reservation.destroy
180
+
181
+ flash[:success] = "予約を削除しました。"
182
+
183
+ redirect_to user_path(current_user.id)
184
+
185
+ else
186
+
187
+ render :reserve
188
+
189
+ end
190
+
191
+ end
192
+
193
+
194
+
195
+ private
196
+
153
- reservation_data
197
+ def reservation_params
198
+
199
+ params.require(:reservation).permit(:day, :time, :user_id, :from_user_id, :start_time)
154
200
 
155
201
  end
156
202
 
@@ -158,102 +204,6 @@
158
204
 
159
205
  ```
160
206
 
161
- app/controllers/reservations_controller.rb
162
-
163
- ```
164
-
165
- class ReservationsController < ApplicationController
166
-
167
- before_action :logged_in_user
168
-
169
-
170
-
171
- def index
172
-
173
- @user = User.find(params[:user_id])
174
-
175
- @reservations = Reservation.where("day >= ?", Date.current).where("day < ?", Date.current >> 3).order(day: :desc).where("user_id = ? or from_user_id = ?", @user.id, current_user.id)
176
-
177
- end
178
-
179
-
180
-
181
- def new
182
-
183
- @user = User.find(params[:user_id])
184
-
185
- @reservation = Reservation.new
186
-
187
- @day = params[:day]
188
-
189
- @time = params[:time]
190
-
191
- @start_time = DateTime.parse(@day + " " + @time + " " + "JST")
192
-
193
- end
194
-
195
-
196
-
197
- def show
198
-
199
- @reservation = Reservation.find(params[:id])
200
-
201
- end
202
-
203
-
204
-
205
- def create
206
-
207
- @reservation = Reservation.new(reservation_params)
208
-
209
- if @reservation.save
210
-
211
- flash[:success] = "ビデオ通話予約しました"
212
-
213
- redirect_to reservation_path @reservation.id
214
-
215
- else
216
-
217
- render :new
218
-
219
- end
220
-
221
- end
222
-
223
-
224
-
225
- def destroy
226
-
227
- @reservation = Reservation.find(params[:id])
228
-
229
- if @reservation.destroy
230
-
231
- flash[:success] = "予約を削除しました。"
232
-
233
- redirect_to user_path(current_user.id)
234
-
235
- else
236
-
237
- render :reserve
238
-
239
- end
240
-
241
- end
242
-
243
-
244
-
245
- private
246
-
247
- def reservation_params
248
-
249
- params.require(:reservation).permit(:day, :time, :user_id, :from_user_id, :start_time)
250
-
251
- end
252
-
253
- end
254
-
255
- ```
256
-
257
207
  app/views/reservations/new.html.erb
258
208
 
259
209
  ```
@@ -320,6 +270,168 @@
320
270
 
321
271
 
322
272
 
273
+ サーバーログ
274
+
275
+ ```
276
+
277
+ Started GET "/reservations?user_id=1" for ::1 at 2021-07-24 11:00:07 +0900
278
+
279
+ Processing by ReservationsController#index as HTML
280
+
281
+ Parameters: {"user_id"=>"1"}
282
+
283
+ User Load (0.9ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
284
+
285
+ ↳ app/helpers/sessions_helper.rb:43
286
+
287
+ User Load (0.8ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
288
+
289
+ ↳ app/controllers/reservations_controller.rb:5
290
+
291
+ Rendering reservations/index.html.erb within layouts/application
292
+
293
+ Reservation Load (53.0ms) SELECT "reservations".* FROM "reservations" WHERE (day >= '2021-07-24') AND (day < '2021-10-24') AND (user_id = 1 or from_user_id = 1) ORDER BY "reservations"."day" DESC
294
+
295
+ ↳ app/views/reservations/index.html.erb:11
296
+
297
+ Reservation Load (0.8ms) SELECT "reservations".* FROM "reservations" WHERE (day >= '2021-07-24') AND (day < '2021-08-24') ORDER BY "reservations"."day" DESC
298
+
299
+ ↳ app/models/reservation.rb:15
300
+
301
+ Rendered simple_calendar/_week_calendar.html.erb (15.1ms)
302
+
303
+ Rendered reservations/index.html.erb within layouts/application (89.1ms)
304
+
305
+ Rendered layouts/_rails_default.html.erb (24.8ms)
306
+
307
+ Rendered layouts/_shim.html.erb (0.5ms)
308
+
309
+ Rendered layouts/_navigation.html.erb (3.4ms)
310
+
311
+ Rendered layouts/_search.html.erb (4.4ms)
312
+
313
+ Rendered layouts/_footer.html.erb (0.5ms)
314
+
315
+ Rendered layouts/_js.html.erb (16.7ms)
316
+
317
+ Completed 200 OK in 188ms (Views: 107.2ms | ActiveRecord: 55.5ms)
318
+
319
+
320
+
321
+
322
+
323
+ Started GET "/reservations/new?day=2021-07-25&time=10%3A00&user_id=1" for ::1 at 2021-07-24 11:00:08 +0900
324
+
325
+ Processing by ReservationsController#new as HTML
326
+
327
+ Parameters: {"day"=>"2021-07-25", "time"=>"10:00", "user_id"=>"1"}
328
+
329
+ User Load (3.9ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
330
+
331
+ ↳ app/helpers/sessions_helper.rb:43
332
+
333
+ User Load (0.8ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
334
+
335
+ ↳ app/controllers/reservations_controller.rb:10
336
+
337
+ Rendering reservations/new.html.erb within layouts/application
338
+
339
+ Rendered shared/_error_messages.html.erb (0.9ms)
340
+
341
+ Rendered reservations/new.html.erb within layouts/application (93.1ms)
342
+
343
+ Rendered layouts/_rails_default.html.erb (21.5ms)
344
+
345
+ Rendered layouts/_shim.html.erb (0.4ms)
346
+
347
+ Rendered layouts/_navigation.html.erb (2.3ms)
348
+
349
+ Rendered layouts/_search.html.erb (1.0ms)
350
+
351
+ Rendered layouts/_footer.html.erb (0.3ms)
352
+
353
+ Rendered layouts/_js.html.erb (7.1ms)
354
+
355
+ Completed 200 OK in 147ms (Views: 135.9ms | ActiveRecord: 4.6ms)
356
+
357
+
358
+
359
+
360
+
361
+ Started POST "/reservations" for ::1 at 2021-07-24 11:00:11 +0900
362
+
363
+ Processing by ReservationsController#create as HTML
364
+
365
+ Parameters: {"utf8"=>"✓", "authenticity_token"=>"uzBu1Xyew30viLVC/AypLZ/h0zfOq9VxzEUyOloFyV8niK9bO8hOX6HmF6Y+UhAX/dul3TDfqlkpIgPgEkzxcA==", "reservation"=>{"day"=>"2021-07-25", "time"=>"10:00", "from_user_id"=>"1", "user_id"=>"1", "start_time"=>"2021-07-25T10:00:00+09:00"}, "commit"=>"登録する"}
366
+
367
+ User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
368
+
369
+ ↳ app/helpers/sessions_helper.rb:43
370
+
371
+ (0.2ms) BEGIN
372
+
373
+ ↳ app/controllers/reservations_controller.rb:23
374
+
375
+ CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
376
+
377
+ ↳ app/controllers/reservations_controller.rb:23
378
+
379
+ Reservation Exists (7.6ms) SELECT 1 AS one FROM "reservations" WHERE "reservations"."start_time" = $1 LIMIT $2 [["start_time", "2021-07-25 01:00:00"], ["LIMIT", 1]]
380
+
381
+ ↳ app/controllers/reservations_controller.rb:23
382
+
383
+ Reservation Create (15.5ms) INSERT INTO "reservations" ("day", "time", "user_id", "created_at", "updated_at", "start_time", "from_user_id") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["day", "2021-07-25"], ["time", "10:00"], ["user_id", 1], ["created_at", "2021-07-24 02:00:11.467966"], ["updated_at", "2021-07-24 02:00:11.467966"], ["start_time", "2021-07-25 01:00:00"], ["from_user_id", 1]]
384
+
385
+ ↳ app/controllers/reservations_controller.rb:23
386
+
387
+ (47.0ms) COMMIT
388
+
389
+ ↳ app/controllers/reservations_controller.rb:23
390
+
391
+ Redirected to http://localhost:3000/reservations/20
392
+
393
+ Completed 302 Found in 125ms (ActiveRecord: 71.9ms)
394
+
395
+
396
+
397
+
398
+
399
+ Started GET "/reservations/20" for ::1 at 2021-07-24 11:00:11 +0900
400
+
401
+ Processing by ReservationsController#show as HTML
402
+
403
+ Parameters: {"id"=>"20"}
404
+
405
+ User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
406
+
407
+ ↳ app/helpers/sessions_helper.rb:43
408
+
409
+ Reservation Load (0.5ms) SELECT "reservations".* FROM "reservations" WHERE "reservations"."id" = $1 LIMIT $2 [["id", 20], ["LIMIT", 1]]
410
+
411
+ ↳ app/controllers/reservations_controller.rb:18
412
+
413
+ Rendering reservations/show.html.erb within layouts/application
414
+
415
+ Rendered reservations/show.html.erb within layouts/application (1.1ms)
416
+
417
+ Rendered layouts/_rails_default.html.erb (8.4ms)
418
+
419
+ Rendered layouts/_shim.html.erb (0.3ms)
420
+
421
+ Rendered layouts/_navigation.html.erb (3.1ms)
422
+
423
+ Rendered layouts/_search.html.erb (1.8ms)
424
+
425
+ Rendered layouts/_footer.html.erb (0.3ms)
426
+
427
+ Rendered layouts/_js.html.erb (7.2ms)
428
+
429
+ Completed 200 OK in 37ms (Views: 30.7ms | ActiveRecord: 1.2ms)
430
+
431
+ ```
432
+
433
+
434
+
323
435
 
324
436
 
325
437
  ### 補足情報(FW/ツールのバージョンなど)