質問編集履歴
5
モデルの記載
title
CHANGED
File without changes
|
body
CHANGED
@@ -71,4 +71,12 @@
|
|
71
71
|
fuga: [:id, :order, :title, :_destroy])
|
72
72
|
end
|
73
73
|
|
74
|
+
```
|
75
|
+
|
76
|
+
**model**
|
77
|
+
|
78
|
+
```
|
79
|
+
class Piyo < ApplicationRecord
|
80
|
+
has_many :hoges, dependent: :destroy
|
81
|
+
has_many :fugas, dependent: :destroy
|
74
82
|
```
|
4
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,8 +5,8 @@
|
|
5
5
|
```
|
6
6
|
Parameters: {"utf8"=>"✓",
|
7
7
|
"authenticity_token"=>"F98xi8sKXsi7vZmlhtGZpTXpMU0DsDv4FexHYHzVRgXpbkoiJF5429GL1+IIPGZMIo
|
8
|
-
"hoge"=>{"0"=>{"title"=>"title1", "order"=>"1"}, "1"=>{"
|
8
|
+
"hoge"=>{"0"=>{"title"=>"title1", "order"=>"1"}, "1"=>{"title"=>"title2",
|
9
|
-
"order"=>"1"}}, "fuga"=>{"0"=>{"
|
9
|
+
"order"=>"1"}}, "fuga"=>{"0"=>{"title"=>"title1", "order"=>"1"}, "1"=>{"title"=>"title2",
|
10
10
|
"order"=>"1"}}
|
11
11
|
"commit"=>"登録"}
|
12
12
|
|
@@ -22,8 +22,8 @@
|
|
22
22
|
```
|
23
23
|
Parameters: {"utf8"=>"✓",
|
24
24
|
"authenticity_token"=>"F98xi8sKXsi7vZmlhtGZpTXpMU0DsDv4FexHYHzVRgXpbkoiJF5429GL1+IIPGZMIo
|
25
|
-
"hoge"=>{"0"=>{"title"=>"title1", "order"=>"1"}, "1"=>{"
|
25
|
+
"hoge"=>{"0"=>{"title"=>"title1", "order"=>"1"}, "1"=>{"title"=>"title2",
|
26
|
-
"order"=>"2"}}, "fuga"=>{"0"=>{"
|
26
|
+
"order"=>"2"}}, "fuga"=>{"0"=>{"title"=>"title1", "order"=>"1"}, "1"=>{"title"=>"title2",
|
27
27
|
"order"=>"2"}}
|
28
28
|
"commit"=>"登録"}
|
29
29
|
```
|
@@ -34,7 +34,7 @@
|
|
34
34
|
`"hoge"=>{"0"` ここの部分は連番とは限らないです
|
35
35
|
|
36
36
|
```
|
37
|
-
"hoge"=>{"1"=>{"title"=>"title1", "order"=>"1"}, "0"=>{"
|
37
|
+
"hoge"=>{"1"=>{"title"=>"title1", "order"=>"1"}, "0"=>{"title"=>"title2",
|
38
38
|
"order"=>"2"}}
|
39
39
|
```
|
40
40
|
|
@@ -67,8 +67,8 @@
|
|
67
67
|
|
68
68
|
private
|
69
69
|
def piyo_params
|
70
|
-
params.require(:piyo).permit(hoge: [:id, :order, :
|
70
|
+
params.require(:piyo).permit(hoge: [:id, :order, :title, :_destroy],
|
71
|
-
fuga: [:id, :order, :
|
71
|
+
fuga: [:id, :order, :title, :_destroy])
|
72
72
|
end
|
73
73
|
|
74
74
|
```
|
3
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -67,7 +67,7 @@
|
|
67
67
|
|
68
68
|
private
|
69
69
|
def piyo_params
|
70
|
-
params.require(:
|
70
|
+
params.require(:piyo).permit(hoge: [:id, :order, :name, :_destroy],
|
71
71
|
fuga: [:id, :order, :name, :_destroy])
|
72
72
|
end
|
73
73
|
|
2
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -65,4 +65,10 @@
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
private
|
69
|
+
def piyo_params
|
70
|
+
params.require(:recipe).permit(hoge: [:id, :order, :name, :_destroy],
|
71
|
+
fuga: [:id, :order, :name, :_destroy])
|
72
|
+
end
|
73
|
+
|
68
74
|
```
|
1
コントローラーの記載
title
CHANGED
File without changes
|
body
CHANGED
@@ -42,4 +42,27 @@
|
|
42
42
|
|
43
43
|
params自体の取得はわかるのですが、そのさきの書き換えがわからず
|
44
44
|
|
45
|
-
どうかご教示お願い致します。
|
45
|
+
どうかご教示お願い致します。
|
46
|
+
|
47
|
+
##追記
|
48
|
+
|
49
|
+
**controller**
|
50
|
+
|
51
|
+
```
|
52
|
+
|
53
|
+
def new
|
54
|
+
@piyo = Piyo.new
|
55
|
+
@hoge.hoge.build
|
56
|
+
@huga.huga.build
|
57
|
+
end
|
58
|
+
|
59
|
+
def create
|
60
|
+
@piyo = Piyo.new(piyo_params)
|
61
|
+
if @piyo.save
|
62
|
+
redirect_to piyos_path
|
63
|
+
else
|
64
|
+
render 'new'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
```
|