質問編集履歴
1
サンプルコードの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -33,3 +33,51 @@
|
|
33
33
|
|
34
34
|
|
35
35
|
参考:[accepts_nested_attributes_forを使わず、複数の子レコードを保存する](https://moneyforward.com/engineers_blog/2018/12/15/formobject/)
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
追記(サンプルコード)
|
42
|
+
|
43
|
+
---
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
上記リンクのモデル・コントローラー名を利用したときは下記のような形になりました。
|
48
|
+
|
49
|
+
```
|
50
|
+
|
51
|
+
#ThoughtsController
|
52
|
+
|
53
|
+
def create
|
54
|
+
|
55
|
+
thoughts_params.each do |thought_params|
|
56
|
+
|
57
|
+
Thought.create(thought_params[1])
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
・
|
62
|
+
|
63
|
+
・
|
64
|
+
|
65
|
+
・
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def thoughts_params
|
70
|
+
|
71
|
+
params.permit(thoughts: [:content,:author])
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
```
|
76
|
+
|
77
|
+
またCreateメソッドが実行するとconsoleで`Unpermitted parameters: :authenticity_token, :commit`が表示されます。
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
こちらは下記が参考になりそうです。
|
82
|
+
|
83
|
+
[https://teratail.com/questions/182766](https://teratail.com/questions/182766)
|