質問するログイン新規登録

質問編集履歴

3

出力結果の訂正

2020/05/24 06:03

投稿

na22ky
na22ky

スコア0

title CHANGED
File without changes
body CHANGED
@@ -19,8 +19,8 @@
19
19
  <input placeholder="食材" id="name[0]" type="text" name="recipe[materials_attributes][0][name]" />
20
20
  <input placeholder="量" id="amount[0]" type="text" name="recipe[materials_attributes][0][amount]" />
21
21
  <div class="material_field" id="material_field[1]">
22
- <input placeholder="食材" id="name[1]" type="text" name="recipe[materials_attributes][0][name]">
22
+ <input placeholder="食材" id="name[1]" type="text" name="recipe[materials_attributes][0][name]" />
23
- <input placeholder="量" id="amount[1]" type="text" name="recipe[materials_attributes][0][amount]">
23
+ <input placeholder="量" id="amount[1]" type="text" name="recipe[materials_attributes][0][amount]" />
24
24
  </div>
25
25
  </div>
26
26
  ```
@@ -60,8 +60,8 @@
60
60
  <input placeholder="食材" id="name[0]" type="text" name="recipe[materials_attributes][0][name]" />
61
61
  <input placeholder="量" id="amount[0]" type="text" name="recipe[materials_attributes][0][amount]" />
62
62
  <div class="material_field" id="material_field[1]">
63
- <input placeholder="食材" id="name[1]" type="text" name="recipe[materials_attributes][1][name]">
63
+ <input placeholder="食材" id="name[1]" type="text" name="recipe[materials_attributes][1][name]" />
64
- <input placeholder="量" id="amount[1]" type="text" name="recipe[materials_attributes][1][amount]">
64
+ <input placeholder="量" id="amount[1]" type="text" name="recipe[materials_attributes][1][amount]" />
65
65
  </div>
66
66
  </div>
67
67
 

2

理想の出力結果の追加

2020/05/24 06:03

投稿

na22ky
na22ky

スコア0

title CHANGED
File without changes
body CHANGED
@@ -16,11 +16,13 @@
16
16
  ```html
17
17
 
18
18
  <div class="material_field" id="material_field[0]">
19
- <input placeholder="食材" id="name[0]" type="text" name="recipe[materials_attributes][0][name]" />
19
+ <input placeholder="食材" id="name[0]" type="text" name="recipe[materials_attributes][0][name]" />
20
- <input placeholder="量" id="amount[0]" type="text" name="recipe[materials_attributes][0][amount]" />
20
+ <input placeholder="量" id="amount[0]" type="text" name="recipe[materials_attributes][0][amount]" />
21
+ <div class="material_field" id="material_field[1]">
22
+ <input placeholder="食材" id="name[1]" type="text" name="recipe[materials_attributes][0][name]">
23
+ <input placeholder="量" id="amount[1]" type="text" name="recipe[materials_attributes][0][amount]">
21
- </div>
24
+ </div>
22
- <button name="button" type="button" id="add_btn">▽追加する</button>
23
- </div>
25
+ </div>
24
26
  ```
25
27
 
26
28
 
@@ -51,4 +53,21 @@
51
53
  });
52
54
 
53
55
  ```
54
- `text_field:name`の`:name`部分を配列にしたい場合はjqueryでどのように指定したら良いのか分からず質問しました。上手く説明ができていないかもしれませんが、回答よろしくお願いします。
56
+ `text_field:name`の`:name`部分を配列にしたい場合はjqueryでどのように指定したら良いのか分からず質問しました。
57
+ ↓理想の出力結果です
58
+ ```HTML
59
+ <div class="material_field" id="material_field[0]">
60
+ <input placeholder="食材" id="name[0]" type="text" name="recipe[materials_attributes][0][name]" />
61
+ <input placeholder="量" id="amount[0]" type="text" name="recipe[materials_attributes][0][amount]" />
62
+ <div class="material_field" id="material_field[1]">
63
+ <input placeholder="食材" id="name[1]" type="text" name="recipe[materials_attributes][1][name]">
64
+ <input placeholder="量" id="amount[1]" type="text" name="recipe[materials_attributes][1][amount]">
65
+ </div>
66
+ </div>
67
+
68
+
69
+ ```
70
+
71
+
72
+
73
+ 上手く説明ができていないかもしれませんが、回答よろしくお願いします。

1

フレームワークと出力結果の追加

2020/05/24 06:02

投稿

na22ky
na22ky

スコア0

title CHANGED
File without changes
body CHANGED
@@ -12,7 +12,18 @@
12
12
  <%= form.button '▽追加する', id: "add_btn",type: "button"%>
13
13
  </div>
14
14
  ```
15
+ ↓出力結果です
16
+ ```html
15
17
 
18
+ <div class="material_field" id="material_field[0]">
19
+ <input placeholder="食材" id="name[0]" type="text" name="recipe[materials_attributes][0][name]" />
20
+ <input placeholder="量" id="amount[0]" type="text" name="recipe[materials_attributes][0][amount]" />
21
+ </div>
22
+ <button name="button" type="button" id="add_btn">▽追加する</button>
23
+ </div>
24
+ ```
25
+
26
+
16
27
  ```js
17
28
  $(function(){
18
29
  // フォームカウント