回答編集履歴
2
tobeのパラメータ更新
test
CHANGED
@@ -80,11 +80,11 @@
|
|
80
80
|
|
81
81
|
"gender"=>"1",
|
82
82
|
|
83
|
-
"user_categories_attributes"=>{
|
83
|
+
"user_categories_attributes"=>[{
|
84
84
|
|
85
85
|
"category_ids"=>["", "1", "3", "4"]
|
86
86
|
|
87
|
-
}
|
87
|
+
}]
|
88
88
|
|
89
89
|
}
|
90
90
|
|
1
collection_check_boxesの書き方について追記
test
CHANGED
@@ -3,3 +3,109 @@
|
|
3
3
|
[https://qiita.com/shingo-nakanishi/items/229ae20bc1ddf7192dfb](https://qiita.com/shingo-nakanishi/items/229ae20bc1ddf7192dfb)
|
4
4
|
|
5
5
|
を参考にして、fileds_forタグを使ってみたらどうでしょう?
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
---
|
10
|
+
|
11
|
+
追記
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
AsIsのパラメーターでは以下のようになっているのですが、、、
|
18
|
+
|
19
|
+
```
|
20
|
+
|
21
|
+
{
|
22
|
+
|
23
|
+
"user"=>{
|
24
|
+
|
25
|
+
"name"=>"test22",
|
26
|
+
|
27
|
+
"email"=>"test22@a.com",
|
28
|
+
|
29
|
+
"password"=>"[FILTERED]",
|
30
|
+
|
31
|
+
"password_confirmation"=>"[FILTERED]",
|
32
|
+
|
33
|
+
"birthday(1i)"=>"1991",
|
34
|
+
|
35
|
+
"birthday(2i)"=>"1",
|
36
|
+
|
37
|
+
"birthday(3i)"=>"1",
|
38
|
+
|
39
|
+
"gender"=>"1"
|
40
|
+
|
41
|
+
},
|
42
|
+
|
43
|
+
"user_categories_attributes"=>{
|
44
|
+
|
45
|
+
"category_ids"=>["", "1", "3", "4"]
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
```
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
正しくは以下のようにならないと、accepts_nested_attributes_forが起動してくれません。
|
58
|
+
|
59
|
+
(※ user_categories_attributesの位置に注目してくださ)
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
{
|
64
|
+
|
65
|
+
"user"=>{
|
66
|
+
|
67
|
+
"name"=>"test22",
|
68
|
+
|
69
|
+
"email"=>"test22@a.com",
|
70
|
+
|
71
|
+
"password"=>"[FILTERED]",
|
72
|
+
|
73
|
+
"password_confirmation"=>"[FILTERED]",
|
74
|
+
|
75
|
+
"birthday(1i)"=>"1991",
|
76
|
+
|
77
|
+
"birthday(2i)"=>"1",
|
78
|
+
|
79
|
+
"birthday(3i)"=>"1",
|
80
|
+
|
81
|
+
"gender"=>"1",
|
82
|
+
|
83
|
+
"user_categories_attributes"=>{
|
84
|
+
|
85
|
+
"category_ids"=>["", "1", "3", "4"]
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
ですので、おそらく対応箇所は以下です(実環境で試してないので、動かなかったらcollection_check_boxes helperのリファレンスを調べてみてください)
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
new.html.erb
|
102
|
+
|
103
|
+
```html
|
104
|
+
|
105
|
+
<%= f.fields_for :category do |fc| %>
|
106
|
+
|
107
|
+
<%= fc.collection_check_boxes :category_ids, Category.all, :id, :name %>
|
108
|
+
|
109
|
+
<% end %>
|
110
|
+
|
111
|
+
```
|