質問編集履歴
6
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -70,6 +70,20 @@
|
|
70
70
|
|
71
71
|
|
72
72
|
|
73
|
+
モデル名:HistoriesDatum
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|Operation_id|namage_id|user_id|user_name|created_at
|
78
|
+
|
79
|
+
|:--|:--:|
|
80
|
+
|
81
|
+
|1|10001|7|tanaka|yyyy/mm/dd/hh:mm
|
82
|
+
|
83
|
+
|2|10002|8|sato|yyyy/mm/dd/hh:mm
|
84
|
+
|
85
|
+
|
86
|
+
|
73
87
|
|
74
88
|
|
75
89
|
### 該当のソースコード
|
5
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -296,7 +296,597 @@
|
|
296
296
|
|
297
297
|
```
|
298
298
|
|
299
|
-
|
299
|
+
item_controller.rb
|
300
|
+
|
301
|
+
```Ruby
|
302
|
+
|
303
|
+
class ItemsController < ApplicationController
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
before_action :authenticate_user
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
def index
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
# データを降順で表示する
|
318
|
+
|
319
|
+
# @items = GyomuDatum.all.order(created_at: 'desc')
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
@items = GyomuDatum.all.includes(:category)
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
# データ検索
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
pp "############データ検索開始############"
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
if params[:manage_id].present?
|
336
|
+
|
337
|
+
items = GyomuDatum.where('manage_id LIKE ?', "%#{params[:manage_id]}%")
|
338
|
+
|
339
|
+
pp "manage_id_debug"
|
340
|
+
|
341
|
+
pp items
|
342
|
+
|
343
|
+
elsif params[:category_id].present?
|
344
|
+
|
345
|
+
items = GyomuDatum.where('category_id LIKE ?', "%#{params[:category_id]}%")
|
346
|
+
|
347
|
+
pp "category_id_debug"
|
348
|
+
|
349
|
+
pp items
|
350
|
+
|
351
|
+
elsif params[:publish_corporation].present?
|
352
|
+
|
353
|
+
items = GyomuDatum.where('publish_corporation LIKE ?', "%#{params[:publish_corporation]}%")
|
354
|
+
|
355
|
+
pp "publish_corporation_debug"
|
356
|
+
|
357
|
+
pp items
|
358
|
+
|
359
|
+
pp items
|
360
|
+
|
361
|
+
elsif params[:ip_address].present?
|
362
|
+
|
363
|
+
items = GyomuDatum.where('ip_address LIKE ?', "%#{params[:ip_address]}%")
|
364
|
+
|
365
|
+
pp "ip_address_debug"
|
366
|
+
|
367
|
+
pp items
|
368
|
+
|
369
|
+
elsif params[:target_server].present?
|
370
|
+
|
371
|
+
items = GyomuDatum.where('target_server LIKE ?', "%#{params[:target_server]}%")
|
372
|
+
|
373
|
+
pp "target_server_debug"
|
374
|
+
|
375
|
+
pp items
|
376
|
+
|
377
|
+
elsif params[:start_date].present?
|
378
|
+
|
379
|
+
items = GyomuDatum.where('start_date LIKE ?', "%#{params[:start_date]}%")
|
380
|
+
|
381
|
+
pp "start_date_debug"
|
382
|
+
|
383
|
+
pp items
|
384
|
+
|
385
|
+
elsif params[:end_date].present?
|
386
|
+
|
387
|
+
items = GyomuDatum.where('end_date LIKE ?', "%#{params[:end_date]}%")
|
388
|
+
|
389
|
+
pp "end_date_debug"
|
390
|
+
|
391
|
+
pp items
|
392
|
+
|
393
|
+
elsif params[:comment].present?
|
394
|
+
|
395
|
+
items = GyomuDatum.where('comment LIKE ?', "%#{params[:comment]}%")
|
396
|
+
|
397
|
+
pp "comment_debug"
|
398
|
+
|
399
|
+
pp items
|
400
|
+
|
401
|
+
else
|
402
|
+
|
403
|
+
items = GyomuDatum.all.order(created_at: 'desc')
|
404
|
+
|
405
|
+
pp "all_debug"
|
406
|
+
|
407
|
+
pp items
|
408
|
+
|
409
|
+
end
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
pp "elseout"
|
414
|
+
|
415
|
+
pp items
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
pp "############データ検索終了############"
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
# ページネーション
|
428
|
+
|
429
|
+
@items = items.page(params[:page]).per(20)
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
# 期限が迫っているデータを検索する
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
# 1ヶ月前
|
438
|
+
|
439
|
+
from = Time.now.at_beginning_of_day
|
440
|
+
|
441
|
+
to = (from + 1.month)
|
442
|
+
|
443
|
+
@items_1month = GyomuDatum.where(end_date: from...to)
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
end
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
def show
|
452
|
+
|
453
|
+
end
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
def new
|
458
|
+
|
459
|
+
@item = GyomuDatum.new
|
460
|
+
|
461
|
+
end
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
def create
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
# 変数定義
|
470
|
+
|
471
|
+
manage_id = params[:manage_id]
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
@item = GyomuDatum.find(params[:id])
|
476
|
+
|
477
|
+
manage_id = @item.manage_id
|
478
|
+
|
479
|
+
category_id = @item.category_id
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
# 現在の時刻取得
|
484
|
+
|
485
|
+
require "date"
|
486
|
+
|
487
|
+
time = DateTime.now
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
# 操作履歴登録
|
492
|
+
|
493
|
+
histories = HistoriesDatum.new({manage_id: manage_id, category_id: category_id, type_id: '1', user_id: session[:user_id], user_name: session[:user_name], created_at: time, updated_at: time, deleted_at: ""})
|
494
|
+
|
495
|
+
histories.save
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
# render plain: params[:GyomuDatum].inspect
|
502
|
+
|
503
|
+
# save
|
504
|
+
|
505
|
+
# @item = Item.new(params[:GyomuDatum])
|
506
|
+
|
507
|
+
# @item = GyomuDatum.new(params.require(:GyomuDatum).permit(:manage_id, :category_id, :publish_corporation, :ip_address, :target_server, :start_date, :end_date, :comment))
|
508
|
+
|
509
|
+
@item = GyomuDatum.new(item_params)
|
510
|
+
|
511
|
+
# @item.save
|
512
|
+
|
513
|
+
# redirect
|
514
|
+
|
515
|
+
# redirect_to items_path
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
|
520
|
+
|
521
|
+
# データ登録判定
|
522
|
+
|
523
|
+
|
524
|
+
|
525
|
+
if @item.save
|
526
|
+
|
527
|
+
@notice_message = "データ登録成功"
|
528
|
+
|
529
|
+
flash[:notice] = @notice_message
|
530
|
+
|
531
|
+
redirect_to items_path
|
532
|
+
|
533
|
+
else
|
534
|
+
|
535
|
+
@notice_message = "データ登録失敗"
|
536
|
+
|
537
|
+
flash[:notice] = @notice_message
|
538
|
+
|
539
|
+
# render plain: @item.errors.inspect
|
540
|
+
|
541
|
+
render 'new'
|
542
|
+
|
543
|
+
end
|
544
|
+
|
545
|
+
end
|
546
|
+
|
547
|
+
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
def edit
|
552
|
+
|
553
|
+
@item = GyomuDatum.find(params[:id])
|
554
|
+
|
555
|
+
end
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
def update
|
560
|
+
|
561
|
+
|
562
|
+
|
563
|
+
# データ更新処理
|
564
|
+
|
565
|
+
|
566
|
+
|
567
|
+
# 変数定義
|
568
|
+
|
569
|
+
@item = GyomuDatum.find(params[:id])
|
570
|
+
|
571
|
+
manage_id = @item.manage_id
|
572
|
+
|
573
|
+
category_id = @item.category_id
|
574
|
+
|
575
|
+
|
576
|
+
|
577
|
+
# 現在の時刻取得
|
578
|
+
|
579
|
+
require "date"
|
580
|
+
|
581
|
+
time = DateTime.now
|
582
|
+
|
583
|
+
|
584
|
+
|
585
|
+
# 操作履歴登録
|
586
|
+
|
587
|
+
histories = HistoriesDatum.new({manage_id: manage_id, category_id: category_id, type_id: '2', user_id: session[:user_id], user_name: session[:user_name], created_at: time, updated_at: time, deleted_at: ""})
|
588
|
+
|
589
|
+
histories.save
|
590
|
+
|
591
|
+
|
592
|
+
|
593
|
+
|
594
|
+
|
595
|
+
# データ編集処理判定
|
596
|
+
|
597
|
+
|
598
|
+
|
599
|
+
if @item.update(item_params)
|
600
|
+
|
601
|
+
@notice_message = "データ編集成功"
|
602
|
+
|
603
|
+
flash[:notice] = @notice_message
|
604
|
+
|
605
|
+
redirect_to items_path
|
606
|
+
|
607
|
+
else
|
608
|
+
|
609
|
+
@notice_message = "データ編集失敗"
|
610
|
+
|
611
|
+
flash[:notice] = @notice_message
|
612
|
+
|
613
|
+
render 'edit'
|
614
|
+
|
615
|
+
end
|
616
|
+
|
617
|
+
end
|
618
|
+
|
619
|
+
|
620
|
+
|
621
|
+
def destroy
|
622
|
+
|
623
|
+
|
624
|
+
|
625
|
+
# データ削除処理
|
626
|
+
|
627
|
+
|
628
|
+
|
629
|
+
# 変数定義
|
630
|
+
|
631
|
+
@item = GyomuDatum.find(params[:id])
|
632
|
+
|
633
|
+
manage_id = @item.manage_id
|
634
|
+
|
635
|
+
category_id = @item.category_id
|
636
|
+
|
637
|
+
|
638
|
+
|
639
|
+
# 現在の時刻取得
|
640
|
+
|
641
|
+
require "date"
|
642
|
+
|
643
|
+
time = DateTime.now
|
644
|
+
|
645
|
+
|
646
|
+
|
647
|
+
# 操作履歴登録
|
648
|
+
|
649
|
+
histories = HistoriesDatum.new({manage_id: manage_id, category_id: category_id, type_id: '3', user_id: session[:user_id], user_name: session[:user_name], created_at: time, updated_at: time, deleted_at: ""})
|
650
|
+
|
651
|
+
histories.save
|
652
|
+
|
653
|
+
|
654
|
+
|
655
|
+
# 削除処理
|
656
|
+
|
657
|
+
@item = GyomuDatum.find(params[:id])
|
658
|
+
|
659
|
+
@item.destroy
|
660
|
+
|
661
|
+
redirect_to items_path
|
662
|
+
|
663
|
+
end
|
664
|
+
|
665
|
+
|
666
|
+
|
667
|
+
|
668
|
+
|
669
|
+
|
670
|
+
|
671
|
+
# cron用メール送信メソッド
|
672
|
+
|
673
|
+
def mail_notice
|
674
|
+
|
675
|
+
|
676
|
+
|
677
|
+
# メール送信実行
|
678
|
+
|
679
|
+
SampleMailer.send_when_limit.deliver
|
680
|
+
|
681
|
+
|
682
|
+
|
683
|
+
end
|
684
|
+
|
685
|
+
|
686
|
+
|
687
|
+
|
688
|
+
|
689
|
+
# プライベートメソッド
|
690
|
+
|
691
|
+
|
692
|
+
|
693
|
+
# private
|
694
|
+
|
695
|
+
# def item_params
|
696
|
+
|
697
|
+
# params.require(:GyomuDatum).permit(:manage_id)
|
698
|
+
|
699
|
+
# params.require(:gyomu_datum).permit(:manage_id, :category_id, :publish_corporation, :ip_address, :target_server, :start_date, :end_date, :comment)
|
700
|
+
|
701
|
+
# params.require.fetch(:GyomuDatum,{}).permit(:manage_id, :category_id, :publish_corporation, :ip_address, :target_server, :start_date, :end_date, :comment)
|
702
|
+
|
703
|
+
# end
|
704
|
+
|
705
|
+
|
706
|
+
|
707
|
+
# プライベートメソッド
|
708
|
+
|
709
|
+
private
|
710
|
+
|
711
|
+
def item_params
|
712
|
+
|
713
|
+
permits = [
|
714
|
+
|
715
|
+
:manage_id,
|
716
|
+
|
717
|
+
:category_id,
|
718
|
+
|
719
|
+
:publish_corporation,
|
720
|
+
|
721
|
+
:ip_address,
|
722
|
+
|
723
|
+
:target_server,
|
724
|
+
|
725
|
+
:start_date,
|
726
|
+
|
727
|
+
:end_date,
|
728
|
+
|
729
|
+
:comment
|
730
|
+
|
731
|
+
]
|
732
|
+
|
733
|
+
params.require(:gyomu_datum).permit(permits)
|
734
|
+
|
735
|
+
end
|
736
|
+
|
737
|
+
|
738
|
+
|
739
|
+
# class範囲終了
|
740
|
+
|
741
|
+
end
|
742
|
+
|
743
|
+
|
744
|
+
|
745
|
+
```
|
746
|
+
|
747
|
+
|
748
|
+
|
749
|
+
edit.html.erb
|
750
|
+
|
751
|
+
```Ruby
|
752
|
+
|
753
|
+
<!-- ↓↓データ編集失敗表示↓↓ -->
|
754
|
+
|
755
|
+
|
756
|
+
|
757
|
+
<% if flash[:notice] %>
|
758
|
+
|
759
|
+
<div class="alert alert-success">
|
760
|
+
|
761
|
+
<%= flash[:notice] %>
|
762
|
+
|
763
|
+
</div>
|
764
|
+
|
765
|
+
<% end %>
|
766
|
+
|
767
|
+
|
768
|
+
|
769
|
+
<!-- ↑↑データ編集失敗表示↑↑ -->
|
770
|
+
|
771
|
+
|
772
|
+
|
773
|
+
<br>
|
774
|
+
|
775
|
+
<br>
|
776
|
+
|
777
|
+
<br>
|
778
|
+
|
779
|
+
<h2>
|
780
|
+
|
781
|
+
<%= form_for @item, url: item_path(@item) do |f| %>
|
782
|
+
|
783
|
+
<p class="rei1">データ編集</p>
|
784
|
+
|
785
|
+
<p>
|
786
|
+
|
787
|
+
管理ID:
|
788
|
+
|
789
|
+
<br>
|
790
|
+
|
791
|
+
<%= f.text_field :manage_id, placeholder: '管理ID' %>
|
792
|
+
|
793
|
+
</p>
|
794
|
+
|
795
|
+
<p>
|
796
|
+
|
797
|
+
カテゴリ:
|
798
|
+
|
799
|
+
<br>
|
800
|
+
|
801
|
+
<% if false %>
|
802
|
+
|
803
|
+
<%= f.select :category_id, [["SSL", "1"], ["ドメイン", "2"] ] %>
|
804
|
+
|
805
|
+
<% end %>
|
806
|
+
|
807
|
+
|
808
|
+
|
809
|
+
<%= f.text_field :category_id, placeholder: 'カテゴリ' %>
|
810
|
+
|
811
|
+
|
812
|
+
|
813
|
+
</p>
|
814
|
+
|
815
|
+
<p>
|
816
|
+
|
817
|
+
発行会社:
|
818
|
+
|
819
|
+
<br>
|
820
|
+
|
821
|
+
<%= f.text_field :publish_corporation, placeholder: '発行会社' %>
|
822
|
+
|
823
|
+
</p>
|
824
|
+
|
825
|
+
<p>
|
826
|
+
|
827
|
+
IPアドレス:
|
828
|
+
|
829
|
+
<br>
|
830
|
+
|
831
|
+
<%= f.text_field :ip_address, placeholder: 'IPアドレス' %>
|
832
|
+
|
833
|
+
</p>
|
834
|
+
|
835
|
+
<p>
|
836
|
+
|
837
|
+
サーバ名:
|
838
|
+
|
839
|
+
<br>
|
840
|
+
|
841
|
+
<%= f.text_field :target_server, placeholder: 'サーバ名' %>
|
842
|
+
|
843
|
+
</p>
|
844
|
+
|
845
|
+
<p>
|
846
|
+
|
847
|
+
有効期限の開始:
|
848
|
+
|
849
|
+
<br>
|
850
|
+
|
851
|
+
<%= f.text_field :start_date, placeholder: '2018-04-01' %>
|
852
|
+
|
853
|
+
</p>
|
854
|
+
|
855
|
+
<p>
|
856
|
+
|
857
|
+
有効期限の終了:
|
858
|
+
|
859
|
+
<br>
|
860
|
+
|
861
|
+
<%= f.text_field :end_date, placeholder: '2018-04-01' %>
|
862
|
+
|
863
|
+
</p>
|
864
|
+
|
865
|
+
<p>
|
866
|
+
|
867
|
+
コメント:
|
868
|
+
|
869
|
+
<br>
|
870
|
+
|
871
|
+
<%= f.text_area :comment, placeholder: 'コメント' %>
|
872
|
+
|
873
|
+
</p>
|
874
|
+
|
875
|
+
<p>
|
876
|
+
|
877
|
+
<br>
|
878
|
+
|
879
|
+
<%= f.submit "編集完了" , class: "btn btn-primary"%>
|
880
|
+
|
881
|
+
</p>
|
882
|
+
|
883
|
+
|
884
|
+
|
885
|
+
|
886
|
+
|
887
|
+
<% end %>
|
888
|
+
|
889
|
+
```
|
300
890
|
|
301
891
|
|
302
892
|
|
4
文章追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,6 +16,28 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
+
試した記載:
|
20
|
+
|
21
|
+
<%= @items.each do |item| %>
|
22
|
+
|
23
|
+
<%= item.manage_id %>
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
<% item.category.each do |p| %>
|
28
|
+
|
29
|
+
<%= p.name %>
|
30
|
+
|
31
|
+
<% end %>
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
<% end %>
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
エラーメッセージ:
|
40
|
+
|
19
41
|
undefined method `each' for #<Category id: 1, name: "SSL">
|
20
42
|
|
21
43
|
|
3
文章変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,9 +12,7 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
-
試行錯誤する中で↓のエラーメッセージが表示されている、また、category_idに1または2しか登録できないことから、
|
15
|
+
試行錯誤する中で↓のエラーメッセージが表示されている、また、category_idに1または2しか登録できないことから、アソシエーションの設定には成功していると思います。
|
16
|
-
|
17
|
-
アソシエーションの設定には成功していると思います。
|
18
16
|
|
19
17
|
|
20
18
|
|
2
パス変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -92,7 +92,7 @@
|
|
92
92
|
|
93
93
|
```
|
94
94
|
|
95
|
-
index.html.erb
|
95
|
+
views/items/index.html.erb
|
96
96
|
|
97
97
|
```Ruby
|
98
98
|
|
1
文章追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,6 +12,16 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
+
試行錯誤する中で↓のエラーメッセージが表示されている、また、category_idに1または2しか登録できないことから、
|
16
|
+
|
17
|
+
アソシエーションの設定には成功していると思います。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
undefined method `each' for #<Category id: 1, name: "SSL">
|
22
|
+
|
23
|
+
|
24
|
+
|
15
25
|
モデル名:GyomuDatum
|
16
26
|
|
17
27
|
|ID|category_id※外部キー|..|..|
|