質問編集履歴
3
情報の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -68,6 +68,18 @@
|
|
68
68
|
|
69
69
|
```controller
|
70
70
|
|
71
|
+
def new
|
72
|
+
|
73
|
+
@item = Item.new
|
74
|
+
|
75
|
+
@item.categories_items.build
|
76
|
+
|
77
|
+
@smalls = Category.where(genre_div: 1)
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
|
71
83
|
def item_params
|
72
84
|
|
73
85
|
params.require(:item).permit(
|
2
情報の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,15 +18,11 @@
|
|
18
18
|
|
19
19
|
```View
|
20
20
|
|
21
|
-
<l
|
21
|
+
<%= f.fields_for :categories_items do |q| %>
|
22
22
|
|
23
|
-
<%=
|
23
|
+
<%= render 'categories_items_fields', f: q %>
|
24
24
|
|
25
|
-
<%= render 'categories_items_fields', f: q %>
|
26
|
-
|
27
|
-
|
25
|
+
<% end %>
|
28
|
-
|
29
|
-
</li>
|
30
26
|
|
31
27
|
<div class = "links">
|
32
28
|
|
@@ -35,3 +31,51 @@
|
|
35
31
|
</div>
|
36
32
|
|
37
33
|
```
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
```View
|
38
|
+
|
39
|
+
<li class="string input optional stringish" id="item_category_input">
|
40
|
+
|
41
|
+
<%= f.label :カテゴリー %>
|
42
|
+
|
43
|
+
<div>
|
44
|
+
|
45
|
+
<%= f.collection_select(:big_category_id, Category.where(genre_div: 0), :id, :name, include_blank: true) %>
|
46
|
+
|
47
|
+
</div>
|
48
|
+
|
49
|
+
</li>
|
50
|
+
|
51
|
+
<li class="string input optional stringish" id="item_category_input">
|
52
|
+
|
53
|
+
<div class="small_category_field">
|
54
|
+
|
55
|
+
<%= f.collection_check_boxes(:small_category_id, Category.where(genre_div: 1), :id, :name, include_hidden: false) do |b| %>
|
56
|
+
|
57
|
+
<%= b.label { b.check_box + b.text} %>
|
58
|
+
|
59
|
+
<% end %>
|
60
|
+
|
61
|
+
</div>
|
62
|
+
|
63
|
+
</li>
|
64
|
+
|
65
|
+
```
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
```controller
|
70
|
+
|
71
|
+
def item_params
|
72
|
+
|
73
|
+
params.require(:item).permit(
|
74
|
+
|
75
|
+
:name, :price, :stock, :handling_time, :maker, :model, :description, :memo, :sold_out_div, { small_category_ids: [] }).merge(
|
76
|
+
|
77
|
+
images: uploaded_images, updated_by: current_admin_user.membername, created_by: current_admin_user.membername)
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
```
|
1
情報の補足
test
CHANGED
File without changes
|
test
CHANGED
@@ -13,3 +13,25 @@
|
|
13
13
|
<ActionController::Parameters {"0"=><ActionController::Parameters {"big_category_id"=>"7", "small_category_id"=>["19", "20", "37"]} permitted: false>, "1591607240334"=>{"big_category_id"=>"11", "small_category_id"=>["19", "20", "26"]}} permitted: false>
|
14
14
|
|
15
15
|
``````1591607240334```の部分を1とかにするやり方はありませんか?追加されるフォームでそれぞれランダムな数字になってしまうので追加されたフォームは1,2,3...と続けて作られるようにしたいです。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
```View
|
20
|
+
|
21
|
+
<li class="string input optional stringish">
|
22
|
+
|
23
|
+
<%= f.fields_for :categories_items do |q| %>
|
24
|
+
|
25
|
+
<%= render 'categories_items_fields', f: q %>
|
26
|
+
|
27
|
+
<% end %>
|
28
|
+
|
29
|
+
</li>
|
30
|
+
|
31
|
+
<div class = "links">
|
32
|
+
|
33
|
+
<%= link_to_add_association 'add new', f, :categories_items, :partial => 'categories_items_fields', :force_non_association_create => true %>
|
34
|
+
|
35
|
+
</div>
|
36
|
+
|
37
|
+
```
|