質問編集履歴
6
返信のため
test
CHANGED
File without changes
|
test
CHANGED
@@ -747,3 +747,21 @@
|
|
747
747
|
|
748
748
|
|
749
749
|
```
|
750
|
+
|
751
|
+
|
752
|
+
|
753
|
+
|
754
|
+
|
755
|
+
|
756
|
+
|
757
|
+
2019.11.28 11:56 追記
|
758
|
+
|
759
|
+
新規作成画面(newアクション)
|
760
|
+
|
761
|
+
![イメージ説明](1ab3f7af3eedc11ad68b7f7b379199c4.png)
|
762
|
+
|
763
|
+
|
764
|
+
|
765
|
+
フォームの内容が反映された詳細画面(showアクション)
|
766
|
+
|
767
|
+
![イメージ説明](52481279bf70a3b63a8148fd143344e2.png)
|
5
返信のため
test
CHANGED
File without changes
|
test
CHANGED
@@ -522,21 +522,7 @@
|
|
522
522
|
|
523
523
|
|
524
524
|
|
525
|
-
|
525
|
+
|
526
|
-
|
527
|
-
![![イメージ説明](b5c127c3f813692b0a65f3b684e13c08.png)](798e1580d5d0ce73d5512e10279274fd.png)
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
![イメージ説明](4bc264002fc33a3ca0285be4da51b89f.png)
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
![イメージ説明](3ecef3eeac3b8857d96757703ac407cf.png)
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
![イメージ説明](430d9ba7beac1ae8939fc280293f250b.png)
|
540
526
|
|
541
527
|
|
542
528
|
|
4
返信のため
test
CHANGED
File without changes
|
test
CHANGED
@@ -440,7 +440,103 @@
|
|
440
440
|
|
441
441
|
|
442
442
|
|
443
|
+
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
2019.11.27 21:49更新
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
_form.html.erb
|
452
|
+
|
453
|
+
```html
|
454
|
+
|
455
|
+
<%= form.hidden_field :stall_id %>
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
<table class = "form">
|
460
|
+
|
461
|
+
<tr>
|
462
|
+
|
463
|
+
<th><%= form.label :number, "個体識別番号" %></th>
|
464
|
+
|
465
|
+
<td><%= form.text_field :number, size: 8 %></td>
|
466
|
+
|
467
|
+
</tr>
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
<tr>
|
472
|
+
|
473
|
+
<th><%= form.label :name, "名号" %></th>
|
474
|
+
|
475
|
+
<td><%= form.text_field :name, size: 50 %></td>
|
476
|
+
|
477
|
+
</tr>
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
<tr>
|
482
|
+
|
483
|
+
<th><%= form.label :birthday, "生年月日",
|
484
|
+
|
485
|
+
for: "cow_birthday_1i" %></th></th>
|
486
|
+
|
487
|
+
<td><%= form.date_select :birthday,start_year: 2010, end_year: Time.current.year,
|
488
|
+
|
489
|
+
use_month_numbers: true %></td>
|
490
|
+
|
491
|
+
</tr>
|
492
|
+
|
493
|
+
<tr>
|
494
|
+
|
495
|
+
<th>状態</th>
|
496
|
+
|
497
|
+
<td>
|
498
|
+
|
499
|
+
<%= form.radio_button :status, 1 %>
|
500
|
+
|
501
|
+
<%= form.label :status_1, "経産牛" %>
|
502
|
+
|
503
|
+
<%= form.radio_button :status, 2 %>
|
504
|
+
|
505
|
+
<%= form.label :status_2, "未経産牛" %>
|
506
|
+
|
507
|
+
</td>
|
508
|
+
|
509
|
+
</table>
|
510
|
+
|
511
|
+
```
|
512
|
+
|
513
|
+
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
|
520
|
+
|
443
|
-
2019.11.27 2
|
521
|
+
2019.11.27 22:49 追記
|
522
|
+
|
523
|
+
|
524
|
+
|
525
|
+
logってこれでいいんでしょうか...
|
526
|
+
|
527
|
+
![![イメージ説明](b5c127c3f813692b0a65f3b684e13c08.png)](798e1580d5d0ce73d5512e10279274fd.png)
|
528
|
+
|
529
|
+
|
530
|
+
|
531
|
+
![イメージ説明](4bc264002fc33a3ca0285be4da51b89f.png)
|
532
|
+
|
533
|
+
|
534
|
+
|
535
|
+
![イメージ説明](3ecef3eeac3b8857d96757703ac407cf.png)
|
536
|
+
|
537
|
+
|
538
|
+
|
539
|
+
![イメージ説明](430d9ba7beac1ae8939fc280293f250b.png)
|
444
540
|
|
445
541
|
|
446
542
|
|
@@ -468,7 +564,7 @@
|
|
468
564
|
|
469
565
|
def new
|
470
566
|
|
471
|
-
@cow = Cow.new(birthday: Date.new(2010,1,1))
|
567
|
+
@cow = Cow.new(birthday: Date.new(2010,1,1),stall_id: params[:stall_id])
|
472
568
|
|
473
569
|
render template:'cows/new'
|
474
570
|
|
@@ -490,7 +586,7 @@
|
|
490
586
|
|
491
587
|
def cow_params
|
492
588
|
|
493
|
-
params.require(:cow).permit(:number, :name, :birthday, :status, :stall)
|
589
|
+
params.require(:cow).permit(:number, :name, :birthday, :status, :stall_id)
|
494
590
|
|
495
591
|
end
|
496
592
|
|
@@ -586,7 +682,7 @@
|
|
586
682
|
|
587
683
|
def new
|
588
684
|
|
589
|
-
@cow = Cow.new(birthday: Date.new(2010,1,1))
|
685
|
+
@cow = Cow.new(birthday: Date.new(2010,1,1),stall_id: params[:stall_id])
|
590
686
|
|
591
687
|
end
|
592
688
|
|
@@ -602,7 +698,7 @@
|
|
602
698
|
|
603
699
|
def cow_params
|
604
700
|
|
605
|
-
params.require(:cow).permit(:number, :name, :birthday, :status, :stall)
|
701
|
+
params.require(:cow).permit(:number, :name, :birthday, :status, :stall_id)
|
606
702
|
|
607
703
|
end
|
608
704
|
|
@@ -665,77 +761,3 @@
|
|
665
761
|
|
666
762
|
|
667
763
|
```
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
ご指摘いただいた変更を反映させたものです。
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
2019.11.27 21:49更新
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
_form.html.erb
|
682
|
-
|
683
|
-
```html
|
684
|
-
|
685
|
-
<%= form.hidden_field :stall_id %>
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
<table class = "form">
|
690
|
-
|
691
|
-
<tr>
|
692
|
-
|
693
|
-
<th><%= form.label :number, "個体識別番号" %></th>
|
694
|
-
|
695
|
-
<td><%= form.text_field :number, size: 8 %></td>
|
696
|
-
|
697
|
-
</tr>
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
<tr>
|
702
|
-
|
703
|
-
<th><%= form.label :name, "名号" %></th>
|
704
|
-
|
705
|
-
<td><%= form.text_field :name, size: 50 %></td>
|
706
|
-
|
707
|
-
</tr>
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
<tr>
|
712
|
-
|
713
|
-
<th><%= form.label :birthday, "生年月日",
|
714
|
-
|
715
|
-
for: "cow_birthday_1i" %></th></th>
|
716
|
-
|
717
|
-
<td><%= form.date_select :birthday,start_year: 2010, end_year: Time.current.year,
|
718
|
-
|
719
|
-
use_month_numbers: true %></td>
|
720
|
-
|
721
|
-
</tr>
|
722
|
-
|
723
|
-
<tr>
|
724
|
-
|
725
|
-
<th>状態</th>
|
726
|
-
|
727
|
-
<td>
|
728
|
-
|
729
|
-
<%= form.radio_button :status, 1 %>
|
730
|
-
|
731
|
-
<%= form.label :status_1, "経産牛" %>
|
732
|
-
|
733
|
-
<%= form.radio_button :status, 2 %>
|
734
|
-
|
735
|
-
<%= form.label :status_2, "未経産牛" %>
|
736
|
-
|
737
|
-
</td>
|
738
|
-
|
739
|
-
</table>
|
740
|
-
|
741
|
-
```
|
3
返信のため
test
CHANGED
File without changes
|
test
CHANGED
@@ -682,10 +682,12 @@
|
|
682
682
|
|
683
683
|
```html
|
684
684
|
|
685
|
+
<%= form.hidden_field :stall_id %>
|
686
|
+
|
687
|
+
|
688
|
+
|
685
689
|
<table class = "form">
|
686
690
|
|
687
|
-
<%= form.hidden_field :stall_id %>
|
688
|
-
|
689
691
|
<tr>
|
690
692
|
|
691
693
|
<th><%= form.label :number, "個体識別番号" %></th>
|
2
返信のため
test
CHANGED
File without changes
|
test
CHANGED
@@ -669,3 +669,71 @@
|
|
669
669
|
|
670
670
|
|
671
671
|
ご指摘いただいた変更を反映させたものです。
|
672
|
+
|
673
|
+
|
674
|
+
|
675
|
+
|
676
|
+
|
677
|
+
2019.11.27 21:49更新
|
678
|
+
|
679
|
+
|
680
|
+
|
681
|
+
_form.html.erb
|
682
|
+
|
683
|
+
```html
|
684
|
+
|
685
|
+
<table class = "form">
|
686
|
+
|
687
|
+
<%= form.hidden_field :stall_id %>
|
688
|
+
|
689
|
+
<tr>
|
690
|
+
|
691
|
+
<th><%= form.label :number, "個体識別番号" %></th>
|
692
|
+
|
693
|
+
<td><%= form.text_field :number, size: 8 %></td>
|
694
|
+
|
695
|
+
</tr>
|
696
|
+
|
697
|
+
|
698
|
+
|
699
|
+
<tr>
|
700
|
+
|
701
|
+
<th><%= form.label :name, "名号" %></th>
|
702
|
+
|
703
|
+
<td><%= form.text_field :name, size: 50 %></td>
|
704
|
+
|
705
|
+
</tr>
|
706
|
+
|
707
|
+
|
708
|
+
|
709
|
+
<tr>
|
710
|
+
|
711
|
+
<th><%= form.label :birthday, "生年月日",
|
712
|
+
|
713
|
+
for: "cow_birthday_1i" %></th></th>
|
714
|
+
|
715
|
+
<td><%= form.date_select :birthday,start_year: 2010, end_year: Time.current.year,
|
716
|
+
|
717
|
+
use_month_numbers: true %></td>
|
718
|
+
|
719
|
+
</tr>
|
720
|
+
|
721
|
+
<tr>
|
722
|
+
|
723
|
+
<th>状態</th>
|
724
|
+
|
725
|
+
<td>
|
726
|
+
|
727
|
+
<%= form.radio_button :status, 1 %>
|
728
|
+
|
729
|
+
<%= form.label :status_1, "経産牛" %>
|
730
|
+
|
731
|
+
<%= form.radio_button :status, 2 %>
|
732
|
+
|
733
|
+
<%= form.label :status_2, "未経産牛" %>
|
734
|
+
|
735
|
+
</td>
|
736
|
+
|
737
|
+
</table>
|
738
|
+
|
739
|
+
```
|
1
返信のため
test
CHANGED
File without changes
|
test
CHANGED
@@ -433,3 +433,239 @@
|
|
433
433
|
フォームを送信する前と後でURLが変わっているので何か起ってはいるのでしょうが具体的にどこがどう間違っているのかわからないです。
|
434
434
|
|
435
435
|
フォームを送信したらフォームに記述された内容を反映したshowアクションへ行けるようにするにはどうすればいいか教えていただきたいです。
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
2019.11.27 20:51追記
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
stalls_controller.rb
|
448
|
+
|
449
|
+
```ruby
|
450
|
+
|
451
|
+
class StallsController < ApplicationController
|
452
|
+
|
453
|
+
def index
|
454
|
+
|
455
|
+
@stall = Stall.includes(:cow).order("stallnumber")
|
456
|
+
|
457
|
+
end
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
def show
|
462
|
+
|
463
|
+
@stall = Stall.includes(:cow).find(params[:id])
|
464
|
+
|
465
|
+
end
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
def new
|
470
|
+
|
471
|
+
@cow = Cow.new(birthday: Date.new(2010,1,1))
|
472
|
+
|
473
|
+
render template:'cows/new'
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
end
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
def edit
|
482
|
+
|
483
|
+
@stall = Stall.includes(:cow).find(params[:id])
|
484
|
+
|
485
|
+
end
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
def cow_params
|
492
|
+
|
493
|
+
params.require(:cow).permit(:number, :name, :birthday, :status, :stall)
|
494
|
+
|
495
|
+
end
|
496
|
+
|
497
|
+
def create
|
498
|
+
|
499
|
+
@cow = Cow.new(cow_params)
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
if @cow.save
|
504
|
+
|
505
|
+
redirect_to @cow, notice: "登録しました。"
|
506
|
+
|
507
|
+
render template:'cows/show'
|
508
|
+
|
509
|
+
else
|
510
|
+
|
511
|
+
render "cows/new"
|
512
|
+
|
513
|
+
end
|
514
|
+
|
515
|
+
end
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
def update
|
520
|
+
|
521
|
+
@stall = Stall.includes(:cow).find(params[:id])
|
522
|
+
|
523
|
+
@stall.assign_attributes(params[:cow])
|
524
|
+
|
525
|
+
if @stall.save
|
526
|
+
|
527
|
+
redirect_to @stall, notice: "更新しました"
|
528
|
+
|
529
|
+
else
|
530
|
+
|
531
|
+
render "edit"
|
532
|
+
|
533
|
+
end
|
534
|
+
|
535
|
+
end
|
536
|
+
|
537
|
+
|
538
|
+
|
539
|
+
def destroy
|
540
|
+
|
541
|
+
@stall = Stall.find(params[:id])
|
542
|
+
|
543
|
+
@stall.destroy
|
544
|
+
|
545
|
+
redirect_to :stall, notice: "削除しました。"
|
546
|
+
|
547
|
+
end
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
def cow_params
|
552
|
+
|
553
|
+
params.require(:cow).permit(:number, :name, :birthday, :status, :stall)
|
554
|
+
|
555
|
+
end
|
556
|
+
|
557
|
+
end
|
558
|
+
|
559
|
+
|
560
|
+
|
561
|
+
```
|
562
|
+
|
563
|
+
|
564
|
+
|
565
|
+
cows_controller.rb
|
566
|
+
|
567
|
+
```ruby
|
568
|
+
|
569
|
+
class CowsController < ApplicationController
|
570
|
+
|
571
|
+
def index
|
572
|
+
|
573
|
+
@stall = Stall.includes(:cow).order("number")
|
574
|
+
|
575
|
+
end
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
def show
|
580
|
+
|
581
|
+
@cow = Cow.find(params[:id])
|
582
|
+
|
583
|
+
end
|
584
|
+
|
585
|
+
|
586
|
+
|
587
|
+
def new
|
588
|
+
|
589
|
+
@cow = Cow.new(birthday: Date.new(2010,1,1))
|
590
|
+
|
591
|
+
end
|
592
|
+
|
593
|
+
|
594
|
+
|
595
|
+
def edit
|
596
|
+
|
597
|
+
@cow = Cow.find(params[:id])
|
598
|
+
|
599
|
+
end
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
def cow_params
|
604
|
+
|
605
|
+
params.require(:cow).permit(:number, :name, :birthday, :status, :stall)
|
606
|
+
|
607
|
+
end
|
608
|
+
|
609
|
+
|
610
|
+
|
611
|
+
def create
|
612
|
+
|
613
|
+
@cow = Cow.new(cow_params)
|
614
|
+
|
615
|
+
if @cow.save
|
616
|
+
|
617
|
+
redirect_to @cow, notice: "登録しました。"
|
618
|
+
|
619
|
+
else
|
620
|
+
|
621
|
+
render "new"
|
622
|
+
|
623
|
+
end
|
624
|
+
|
625
|
+
end
|
626
|
+
|
627
|
+
|
628
|
+
|
629
|
+
def update
|
630
|
+
|
631
|
+
@cow = Cow.find(params[:id])
|
632
|
+
|
633
|
+
@cow.assign_attributes(params[:cow])
|
634
|
+
|
635
|
+
if @cow.save
|
636
|
+
|
637
|
+
redirect_to @cow, notice: "更新しました"
|
638
|
+
|
639
|
+
else
|
640
|
+
|
641
|
+
render "edit"
|
642
|
+
|
643
|
+
end
|
644
|
+
|
645
|
+
end
|
646
|
+
|
647
|
+
|
648
|
+
|
649
|
+
def destroy
|
650
|
+
|
651
|
+
@cow = Cow.find(params[:id])
|
652
|
+
|
653
|
+
@cow.destroy
|
654
|
+
|
655
|
+
redirect_to :cow, notice: "削除しました。"
|
656
|
+
|
657
|
+
end
|
658
|
+
|
659
|
+
|
660
|
+
|
661
|
+
|
662
|
+
|
663
|
+
end
|
664
|
+
|
665
|
+
|
666
|
+
|
667
|
+
```
|
668
|
+
|
669
|
+
|
670
|
+
|
671
|
+
ご指摘いただいた変更を反映させたものです。
|