質問編集履歴
5
12月24日追記:エラー画面追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -592,78 +592,76 @@
|
|
592
592
|
|
593
593
|
|
594
594
|
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
上
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
```
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
a
|
644
|
-
|
645
|
-
a
|
646
|
-
|
647
|
-
a
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
```
|
595
|
+
|
596
|
+
|
597
|
+
|
598
|
+
|
599
|
+
### ターミナル上のアップデートが失敗した時のエラー表示
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
```html
|
604
|
+
|
605
|
+
Started PATCH "/users/4/schedules/" for ::1 at 2019-12-24 21:56:32 +0900
|
606
|
+
|
607
|
+
|
608
|
+
|
609
|
+
ActionController::RoutingError (No route matches [PATCH] "/users/4/schedules"):
|
610
|
+
|
611
|
+
|
612
|
+
|
613
|
+
actionpack (5.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
|
614
|
+
|
615
|
+
web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
|
616
|
+
|
617
|
+
web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call'
|
618
|
+
|
619
|
+
web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
|
620
|
+
|
621
|
+
web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
|
622
|
+
|
623
|
+
actionpack (5.2.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
|
624
|
+
|
625
|
+
railties (5.2.3) lib/rails/rack/logger.rb:38:in `call_app'
|
626
|
+
|
627
|
+
railties (5.2.3) lib/rails/rack/logger.rb:26:in `block in call'
|
628
|
+
|
629
|
+
activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `block in tagged'
|
630
|
+
|
631
|
+
activesupport (5.2.3) lib/active_support/tagged_logging.rb:28:in `tagged'
|
632
|
+
|
633
|
+
activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `tagged'
|
634
|
+
|
635
|
+
railties (5.2.3) lib/rails/rack/logger.rb:26:in `call'
|
636
|
+
|
637
|
+
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
|
638
|
+
|
639
|
+
actionpack (5.2.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
|
640
|
+
|
641
|
+
actionpack (5.2.3) lib/action_dispatch/middleware/request_id.rb:27:in `call'
|
642
|
+
|
643
|
+
rack (2.0.8) lib/rack/method_override.rb:22:in `call'
|
644
|
+
|
645
|
+
rack (2.0.8) lib/rack/runtime.rb:22:in `call'
|
646
|
+
|
647
|
+
activesupport (5.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
|
648
|
+
|
649
|
+
actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
|
650
|
+
|
651
|
+
actionpack (5.2.3) lib/action_dispatch/middleware/static.rb:127:in `call'
|
652
|
+
|
653
|
+
rack (2.0.8) lib/rack/sendfile.rb:111:in `call'
|
654
|
+
|
655
|
+
railties (5.2.3) lib/rails/engine.rb:524:in `call'
|
656
|
+
|
657
|
+
puma (3.12.2) lib/puma/configuration.rb:227:in `call'
|
658
|
+
|
659
|
+
puma (3.12.2) lib/puma/server.rb:674:in `handle_request'
|
660
|
+
|
661
|
+
puma (3.12.2) lib/puma/server.rb:476:in `process_client'
|
662
|
+
|
663
|
+
puma (3.12.2) lib/puma/server.rb:334:in `block in run'
|
664
|
+
|
665
|
+
puma (3.12.2) lib/puma/thread_pool.rb:135:in `block in spawn_thread'
|
666
|
+
|
667
|
+
```
|
4
12月24日追記:エラー画面
test
CHANGED
File without changes
|
test
CHANGED
@@ -589,3 +589,81 @@
|
|
589
589
|
})
|
590
590
|
|
591
591
|
```
|
592
|
+
|
593
|
+
|
594
|
+
|
595
|
+
## 12月24日追記
|
596
|
+
|
597
|
+
viewのdata-schedule-idに"<%=user.schedules.order(in: :desc).first.id%>"を挿入した際に出るエラー画面の内容です。
|
598
|
+
|
599
|
+
上記を挿入後、リロードすると以下のエラー画面が表示されます。
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
```view
|
604
|
+
|
605
|
+
NoMethodError in Users#index <- 一番上の赤い帯部分に表示されるエラーです
|
606
|
+
|
607
|
+
|
608
|
+
|
609
|
+
Showing /Users/hoge/アプリが入ってるファイル名/アプリ名/app/views/users/_employee.html.erb where line #3 raised:
|
610
|
+
|
611
|
+
|
612
|
+
|
613
|
+
undefined method `id' for nil:NilClass
|
614
|
+
|
615
|
+
Extracted source (around line #3):
|
616
|
+
|
617
|
+
|
618
|
+
|
619
|
+
---------ボックス内に表示されるコード---------------------------
|
620
|
+
|
621
|
+
<% @users.each do |user| %>
|
622
|
+
|
623
|
+
<ul class="employee__box__list">
|
624
|
+
|
625
|
+
<li class="employee__box__list__name", id="leave", value="<%=user.id%>" data-user-id="<%=user.id%>", data-schedule-id="<%=user.schedules.order(in: :desc).first.id%>"><%= user.name %></li> <- この部分に色がついています。
|
626
|
+
|
627
|
+
</ul>
|
628
|
+
|
629
|
+
<% end %>
|
630
|
+
|
631
|
+
----------------------------------------------------------
|
632
|
+
|
633
|
+
Trace of template inclusion: app/views/users/index.html.erb
|
634
|
+
|
635
|
+
|
636
|
+
|
637
|
+
Rails.root: /Users/hoge/アプリが入っているファイル名/アプリ名
|
638
|
+
|
639
|
+
|
640
|
+
|
641
|
+
Application Trace | Framework Trace | Full Trace
|
642
|
+
|
643
|
+
app/views/users/_employee.html.erb:3:in `block in _app_views_users__employee_html_erb___3489706940194667954_70265714907200'
|
644
|
+
|
645
|
+
app/views/users/_employee.html.erb:1:in `_app_views_users__employee_html_erb___3489706940194667954_70265714907200'
|
646
|
+
|
647
|
+
app/views/users/index.html.erb:3:in `_app_views_users_index_html_erb___306235934780249853_70265715004260'
|
648
|
+
|
649
|
+
Request
|
650
|
+
|
651
|
+
Parameters:
|
652
|
+
|
653
|
+
|
654
|
+
|
655
|
+
None
|
656
|
+
|
657
|
+
Toggle session dump
|
658
|
+
|
659
|
+
Toggle env dump
|
660
|
+
|
661
|
+
Response
|
662
|
+
|
663
|
+
Headers:
|
664
|
+
|
665
|
+
|
666
|
+
|
667
|
+
None
|
668
|
+
|
669
|
+
```
|
3
12月23日追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -355,3 +355,237 @@
|
|
355
355
|
また、上記コード以外で不足部分がございましたら、追記いたしますのでお伝え下さい。
|
356
356
|
|
357
357
|
よろしくお願いします。
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
## 12月23日追記
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
現在のコード状況です。
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
```erb
|
372
|
+
|
373
|
+
<% @users.each do |user| %>
|
374
|
+
|
375
|
+
<ul class="employee__box__list">
|
376
|
+
|
377
|
+
<li class="employee__box__list__name", id="leave", data-user-id="<%=user.id%>", data-schedule-id="<%=user.schedules.ids.last%>"><%= user.name %></li>
|
378
|
+
|
379
|
+
</ul>
|
380
|
+
|
381
|
+
<% end %>
|
382
|
+
|
383
|
+
```
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
schedules_controller
|
388
|
+
|
389
|
+
```Rails
|
390
|
+
|
391
|
+
class SchedulesController < ApplicationController
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
def index
|
396
|
+
|
397
|
+
@schedules = Schedule.where(schedule_params)
|
398
|
+
|
399
|
+
end
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
def new
|
404
|
+
|
405
|
+
@schedule = Schedule.new
|
406
|
+
|
407
|
+
end
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
def create
|
412
|
+
|
413
|
+
@schedule = Schedule.new(in: params[:sch], user_id: schedule_params[:user_id])
|
414
|
+
|
415
|
+
@schedule.save
|
416
|
+
|
417
|
+
respond_to do |format|
|
418
|
+
|
419
|
+
format.html {redirect_to ("/")}
|
420
|
+
|
421
|
+
format.json
|
422
|
+
|
423
|
+
end
|
424
|
+
|
425
|
+
end
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
def update
|
432
|
+
|
433
|
+
user = User.find(schedule_params[:user_id])
|
434
|
+
|
435
|
+
@schedule = Schedule.find(user.schedules.ids.last)
|
436
|
+
|
437
|
+
binding.pry
|
438
|
+
|
439
|
+
binding.pry
|
440
|
+
|
441
|
+
@schedule.update(out: params[:sch])
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
respond_to do |format|
|
448
|
+
|
449
|
+
format.html {redirect_to ("/")}
|
450
|
+
|
451
|
+
format.json
|
452
|
+
|
453
|
+
end
|
454
|
+
|
455
|
+
end
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
private
|
464
|
+
|
465
|
+
def schedule_params
|
466
|
+
|
467
|
+
params.permit(:in, :out, :user_id)
|
468
|
+
|
469
|
+
end
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
end
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
```
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
binding.pryで見る限りでは、@scheduleはアップデートしたいschedule.idを取得できています。
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
```jQuery
|
490
|
+
|
491
|
+
$(document).on('turbolinks:load', function(){
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
$(".employee__box__list__name").click(function(){
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
let time = new Date
|
500
|
+
|
501
|
+
let hour = time.getHours();
|
502
|
+
|
503
|
+
let minute = time.getMinutes();
|
504
|
+
|
505
|
+
let second = time.getSeconds();
|
506
|
+
|
507
|
+
let schedule = hour+":"+minute+":"+second
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
let user_id = $(this).data('user-id');
|
512
|
+
|
513
|
+
let url = '/users/' + user_id + '/schedules';
|
514
|
+
|
515
|
+
console.log("user-id取得", user_id)
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
if($(this).prop('id') == 'leave'){
|
520
|
+
|
521
|
+
$(this).prop('id', 'attend');
|
522
|
+
|
523
|
+
$(this).addClass('employee__box__list__name_select');
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
$.ajax({
|
528
|
+
|
529
|
+
url: url,
|
530
|
+
|
531
|
+
type: "POST",
|
532
|
+
|
533
|
+
data: {sch: schedule},
|
534
|
+
|
535
|
+
dataType: 'json'
|
536
|
+
|
537
|
+
})
|
538
|
+
|
539
|
+
|
540
|
+
|
541
|
+
.done(function(data){
|
542
|
+
|
543
|
+
var data_id = data.id
|
544
|
+
|
545
|
+
$(".employee__box__list__name").attr('data-id', data_id)
|
546
|
+
|
547
|
+
console.log("jsonからのデータ",data_id)
|
548
|
+
|
549
|
+
})
|
550
|
+
|
551
|
+
|
552
|
+
|
553
|
+
.fail(function(data){
|
554
|
+
|
555
|
+
alert('出勤できてません');
|
556
|
+
|
557
|
+
})
|
558
|
+
|
559
|
+
|
560
|
+
|
561
|
+
}else{
|
562
|
+
|
563
|
+
let schedule_id = $(this).data('id');
|
564
|
+
|
565
|
+
let update_schedule = $(this).data('schedule-id');
|
566
|
+
|
567
|
+
console.log("updateしたいschedule.id", update_schedule)
|
568
|
+
|
569
|
+
let update_url = '/users/' + user_id + '/schedules/' + update_schedule;
|
570
|
+
|
571
|
+
$(this).prop('id', 'leave');
|
572
|
+
|
573
|
+
$(this).removeClass('employee__box__list__name_select');
|
574
|
+
|
575
|
+
$.ajax({
|
576
|
+
|
577
|
+
url: update_url,
|
578
|
+
|
579
|
+
type: "PATCH",
|
580
|
+
|
581
|
+
data: {sch: schedule},
|
582
|
+
|
583
|
+
dataType: 'json'
|
584
|
+
|
585
|
+
})
|
586
|
+
|
587
|
+
}
|
588
|
+
|
589
|
+
})
|
590
|
+
|
591
|
+
```
|
2
jQueryを修正しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -258,7 +258,7 @@
|
|
258
258
|
|
259
259
|
let url = '/users/' + user_id + '/schedules';
|
260
260
|
|
261
|
-
console.log("user-id取得", user_id)
|
261
|
+
console.log("user-id取得", user_id)
|
262
262
|
|
263
263
|
|
264
264
|
|
@@ -290,7 +290,7 @@
|
|
290
290
|
|
291
291
|
$(".employee__box__list__name").attr('data-id', data_id)
|
292
292
|
|
293
|
-
console.log("jsonからのデータ",data_id)
|
293
|
+
console.log("jsonからのデータ",data_id)
|
294
294
|
|
295
295
|
})
|
296
296
|
|
@@ -308,14 +308,18 @@
|
|
308
308
|
|
309
309
|
let schedule_id = $(this).data('id');
|
310
310
|
|
311
|
+
let update_schedule = $(this).data('schedule-id'); <- 追記した部分です
|
312
|
+
|
313
|
+
console.log("updateしたいschedule.id", update_schedule) <- consoleで確認するとupdate_scheduleは""になってます
|
314
|
+
|
315
|
+
|
316
|
+
|
311
|
-
let update_url = '/users/' + user_id + '/schedules/' + schedule_id;
|
317
|
+
let update_url = '/users/' + user_id + '/schedules/' + schedule_id; <- このschedule_id部分を各userのschedule.idにしたいです。
|
312
318
|
|
313
319
|
$(this).prop('id', 'leave');
|
314
320
|
|
315
321
|
$(this).removeClass('employee__box__list__name_select');
|
316
322
|
|
317
|
-
|
318
|
-
|
319
323
|
$.ajax({
|
320
324
|
|
321
325
|
url: update_url,
|
1
users_controllerを追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
-
|
19
|
+
schedules_Controller
|
20
20
|
|
21
21
|
```Rails
|
22
22
|
|
@@ -98,6 +98,116 @@
|
|
98
98
|
|
99
99
|
```
|
100
100
|
|
101
|
+
users_controller
|
102
|
+
|
103
|
+
```Rails
|
104
|
+
|
105
|
+
class UsersController < ApplicationController
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
def index
|
110
|
+
|
111
|
+
@users = User.all.order("id")
|
112
|
+
|
113
|
+
get_schedule_id
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
def get_schedule_id <= schedule.idを取得するために使うメソッド、indexに渡して一覧で@schedule.idでscheduleのidを取得できるようにしている。
|
120
|
+
|
121
|
+
@schedules = Schedule.all
|
122
|
+
|
123
|
+
@schedules.each do |sch|
|
124
|
+
|
125
|
+
@schedule = sch
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
def new
|
134
|
+
|
135
|
+
@user = User.new
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
def create
|
142
|
+
|
143
|
+
@user = User.new(name: user_params[:name], email: user_params[:email], password: user_params[:password])
|
144
|
+
|
145
|
+
@user.save
|
146
|
+
|
147
|
+
redirect_to("/")
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
def edit
|
154
|
+
|
155
|
+
@user = User.find(params[:id])
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
def update
|
162
|
+
|
163
|
+
@user = User.find(params[:id])
|
164
|
+
|
165
|
+
@user.update(user_params)
|
166
|
+
|
167
|
+
redirect_to("/users/show")
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
def show
|
174
|
+
|
175
|
+
@users = User.all.order("id")
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
def destroy
|
182
|
+
|
183
|
+
user = User.find(params[:id])
|
184
|
+
|
185
|
+
user.destroy
|
186
|
+
|
187
|
+
redirect_to("/users/show")
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
private
|
194
|
+
|
195
|
+
def user_params
|
196
|
+
|
197
|
+
params.require(:user).permit(:name, :email, :password)
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
```
|
208
|
+
|
209
|
+
|
210
|
+
|
101
211
|
Userが一覧されるhtml.erbのrender部分(html.erbです)
|
102
212
|
|
103
213
|
```erb
|