質問編集履歴
4
コントローラのコードを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -294,6 +294,46 @@
|
|
294
294
|
|
295
295
|
|
296
296
|
|
297
|
+
```postscontroller
|
298
|
+
|
299
|
+
def new
|
300
|
+
|
301
|
+
@post = Post.new
|
302
|
+
|
303
|
+
programs = @post.programs.build
|
304
|
+
|
305
|
+
hards = programs.hards.build
|
306
|
+
|
307
|
+
products = hards.products.build
|
308
|
+
|
309
|
+
end
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
def create
|
314
|
+
|
315
|
+
@post = Post.new(post_params)
|
316
|
+
|
317
|
+
@post.save
|
318
|
+
|
319
|
+
end
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
private
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
def post_params
|
328
|
+
|
329
|
+
params.require(:post).permit(:facility_name, :address, :tell, :registration_date, :estimate_sheet, :delivery_date, :delivery_note, :postal_code, :user_id, programs_attributes:[:software, :user, :post_id, hards_attributes:[:category, :program_id, :_destroy, products_attributes:[:thing, :user_id, :hard_id]]]).merge(user_id: current_user.id)
|
330
|
+
|
331
|
+
end
|
332
|
+
|
333
|
+
```
|
334
|
+
|
335
|
+
|
336
|
+
|
297
337
|
### 試したこと
|
298
338
|
|
299
339
|
|
3
インデントのズレを修正。
test
CHANGED
File without changes
|
test
CHANGED
@@ -68,6 +68,148 @@
|
|
68
68
|
|
69
69
|
.best-main
|
70
70
|
|
71
|
+
.best-main-text
|
72
|
+
|
73
|
+
ハード
|
74
|
+
|
75
|
+
= d.fields_for :hards, class:"hards-parent" do |m|
|
76
|
+
|
77
|
+
= m.text_field :category, placeholder: "category", type: "text", class:"hards-input-text", id: "hard_text"
|
78
|
+
|
79
|
+
= icon('far', 'plus-square', id: 'pulas-hard')
|
80
|
+
|
81
|
+
#add
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
以下は全体のコードです。
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
### 該当のソースコード
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
```HAML
|
98
|
+
|
99
|
+
= render 'partial/sidebar'
|
100
|
+
|
101
|
+
.main
|
102
|
+
|
103
|
+
%span.main-child
|
104
|
+
|
105
|
+
施設情報・納品情報を登録してください
|
106
|
+
|
107
|
+
.main-registration__date
|
108
|
+
|
109
|
+
.main-registration__date-child
|
110
|
+
|
111
|
+
登録日
|
112
|
+
|
113
|
+
= form_for @post, url: posts_path do |f|
|
114
|
+
|
115
|
+
=f.text_field :registration_date, placeholder: "登録日", type: "text", class:"registration__date-input-text"
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
.main-facility
|
120
|
+
|
121
|
+
.main-facility-child
|
122
|
+
|
123
|
+
施設名
|
124
|
+
|
125
|
+
=f.text_field :facility_name, placeholder: "施設名", type: "text", class:"facility-input-text"
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
.main-postal__code
|
130
|
+
|
131
|
+
.main-postal__code-child
|
132
|
+
|
133
|
+
郵便番号
|
134
|
+
|
135
|
+
=f.text_field :postal_code, placeholder: "郵便番号", type: "text", class:"postal__code-input-text"
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
.main-address
|
140
|
+
|
141
|
+
.main-address-child
|
142
|
+
|
143
|
+
住所
|
144
|
+
|
145
|
+
=f.text_field :address, placeholder: "住所", type: "text", class:"address-input-text"
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
.main-tell
|
150
|
+
|
151
|
+
.main-tell-child
|
152
|
+
|
153
|
+
電話番号
|
154
|
+
|
155
|
+
=f.text_field :tell, placeholder: "電話番号", type: "text", class:"tell-input-text"
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
.main-delivery_date
|
160
|
+
|
161
|
+
.main-delivery_date-child
|
162
|
+
|
163
|
+
納品日
|
164
|
+
|
165
|
+
=f.text_field :delivery_date, placeholder: "納品日", type: "text", class:"delivery_date-input-text"
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
.main-delivery_note
|
170
|
+
|
171
|
+
.main-delivery_note-child
|
172
|
+
|
173
|
+
納品書
|
174
|
+
|
175
|
+
= f.file_field :delivery_note, class: "delivery_note-image"
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
.main-estimate_sheet
|
180
|
+
|
181
|
+
.main-estimate_sheet-child
|
182
|
+
|
183
|
+
見積書
|
184
|
+
|
185
|
+
= f.file_field :estimate_sheet, class: "estimate_sheet-image"
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
.footer
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
.best
|
194
|
+
|
195
|
+
%span.best-name
|
196
|
+
|
197
|
+
納品/ソフトウェアを登録してください
|
198
|
+
|
199
|
+
.best-software
|
200
|
+
|
201
|
+
.best-software-child
|
202
|
+
|
203
|
+
ソフト
|
204
|
+
|
205
|
+
= f.fields_for :programs do |d|
|
206
|
+
|
207
|
+
= d.text_field :software, placeholder: "name", type: "text", class:"software-input-text"
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
.best-main
|
212
|
+
|
71
213
|
.best-main-text
|
72
214
|
|
73
215
|
ハード
|
@@ -80,213 +222,97 @@
|
|
80
222
|
|
81
223
|
#add
|
82
224
|
|
225
|
+
|
226
|
+
|
227
|
+
.products
|
228
|
+
|
229
|
+
.products-text
|
230
|
+
|
231
|
+
プロダクト
|
232
|
+
|
233
|
+
= m.fields_for :products do |s|
|
234
|
+
|
235
|
+
= s.text_field :thing, placeholder: "products", type: "text", class:"products-input-text"
|
236
|
+
|
237
|
+
= icon('far', 'plus-square', id: 'pulas-product')
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
.footer
|
242
|
+
|
243
|
+
= f.submit "send", class:"products_button"
|
244
|
+
|
83
245
|
```
|
84
246
|
|
85
247
|
|
86
248
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
``
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
.
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
.main-postal__code-child
|
132
|
-
|
133
|
-
郵便番号
|
134
|
-
|
135
|
-
=f.text_field :postal_code, placeholder: "郵便番号", type: "text", class:"postal__code-input-text"
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
.main-address
|
140
|
-
|
141
|
-
.main-address-child
|
142
|
-
|
143
|
-
住所
|
144
|
-
|
145
|
-
=f.text_field :address, placeholder: "住所", type: "text", class:"address-input-text"
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
.main-tell
|
150
|
-
|
151
|
-
.main-tell-child
|
152
|
-
|
153
|
-
電話番号
|
154
|
-
|
155
|
-
=f.text_field :tell, placeholder: "電話番号", type: "text", class:"tell-input-text"
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
.main-delivery_date
|
160
|
-
|
161
|
-
.main-delivery_date-child
|
162
|
-
|
163
|
-
納品日
|
164
|
-
|
165
|
-
=f.text_field :delivery_date, placeholder: "納品日", type: "text", class:"delivery_date-input-text"
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
.main-delivery_note
|
170
|
-
|
171
|
-
.main-delivery_note-child
|
172
|
-
|
173
|
-
納品書
|
174
|
-
|
175
|
-
= f.file_field :delivery_note, class: "delivery_note-image"
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
.main-estimate_sheet
|
180
|
-
|
181
|
-
.main-estimate_sheet-child
|
182
|
-
|
183
|
-
見積書
|
184
|
-
|
185
|
-
= f.file_field :estimate_sheet, class: "estimate_sheet-image"
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
.footer
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
.best
|
194
|
-
|
195
|
-
%span.best-name
|
196
|
-
|
197
|
-
納品/ソフトウェアを登録してください
|
198
|
-
|
199
|
-
.best-software
|
200
|
-
|
201
|
-
.best-software-child
|
202
|
-
|
203
|
-
ソフト
|
204
|
-
|
205
|
-
= f.fields_for :programs do |d|
|
206
|
-
|
207
|
-
= d.text_field :software, placeholder: "name", type: "text", class:"software-input-text"
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
.best-main
|
212
|
-
|
213
|
-
.best-main-text
|
214
|
-
|
215
|
-
ハード
|
216
|
-
|
217
|
-
= d.fields_for :hards, class:"hards-parent" do |m|
|
218
|
-
|
219
|
-
= m.text_field :category, placeholder: "category", type: "text", class:"hards-input-text", id: "hard_text"
|
220
|
-
|
221
|
-
= icon('far', 'plus-square', id: 'pulas-hard')
|
222
|
-
|
223
|
-
#add
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
.products
|
228
|
-
|
229
|
-
.products-text
|
230
|
-
|
231
|
-
プロダクト
|
232
|
-
|
233
|
-
= m.fields_for :products do |s|
|
234
|
-
|
235
|
-
= s.text_field :thing, placeholder: "products", type: "text", class:"products-input-text"
|
236
|
-
|
237
|
-
= icon('far', 'plus-square', id: 'pulas-product')
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
.footer
|
242
|
-
|
243
|
-
= f.submit "send", class:"products_button"
|
249
|
+
```javascript
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
$(function(){
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
function buildHTML(){
|
258
|
+
|
259
|
+
let html = `<input placeholder="category" type="text" class="hards-input-text" id="hard_text" name="post[programs_attributes][0][hards_attributes][0][category]">`
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
return html;
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
$("#pulas-hard").click(function(e){
|
270
|
+
|
271
|
+
e.preventDefault();
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
let html = buildHTML();
|
276
|
+
|
277
|
+
let type_text = document.getElementById("hard_text").getAttribute("type");
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
$("#add").addClass("add_text");
|
282
|
+
|
283
|
+
$(".add_text").append(html);
|
284
|
+
|
285
|
+
$(".add_text").attr(type_text);
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
});
|
290
|
+
|
291
|
+
});
|
244
292
|
|
245
293
|
```
|
246
294
|
|
247
295
|
|
248
296
|
|
297
|
+
### 試したこと
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
getElementByIdで要素を取得してしまったからオリジナルのフォームの値は保存されないのかと思い、
|
302
|
+
|
303
|
+
オリジナルのクローンを作る、書き方に変更して試してみました。
|
304
|
+
|
305
|
+
ですが、今度はオリジナルは保存できて、追加した項目の値が保存されないようになりました。
|
306
|
+
|
307
|
+
|
308
|
+
|
249
309
|
```javascript
|
250
310
|
|
251
|
-
|
252
|
-
|
253
|
-
$(function(){
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
function buildHTML(){
|
258
|
-
|
259
|
-
let html = `<input placeholder="category" type="text" class="hards-input-text" id="hard_text" name="post[programs_attributes][0][hards_attributes][0][category]">`
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
return html;
|
264
|
-
|
265
|
-
}
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
311
|
+
$(document).on("click", "#pulas-hard", function() {
|
270
|
-
|
271
|
-
|
312
|
+
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
313
|
+
|
276
|
-
|
277
|
-
|
314
|
+
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
315
|
+
$("#hard_text").clone(true).insertAfter("#hard_text");
|
282
|
-
|
283
|
-
$(".add_text").append(html);
|
284
|
-
|
285
|
-
$(".add_text").attr(type_text);
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
});
|
290
316
|
|
291
317
|
});
|
292
318
|
|
@@ -294,32 +320,6 @@
|
|
294
320
|
|
295
321
|
|
296
322
|
|
297
|
-
### 試したこと
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
getElementByIdで要素を取得してしまったからオリジナルのフォームの値は保存されないのかと思い、
|
302
|
-
|
303
|
-
オリジナルのクローンを作る、書き方に変更して試してみました。
|
304
|
-
|
305
|
-
ですが、今度はオリジナルは保存できて、追加した項目の値が保存されないようになりました。
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
```javascript
|
310
|
-
|
311
|
-
$(document).on("click", "#pulas-hard", function() {
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
$("#hard_text").clone(true).insertAfter("#hard_text");
|
316
|
-
|
317
|
-
});
|
318
|
-
|
319
|
-
```
|
320
|
-
|
321
|
-
|
322
|
-
|
323
323
|
### 最終的にどうしたいか、具体的に
|
324
324
|
|
325
325
|
|
2
わかりやすい見た目にするため、抜粋したコードを記述。
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,13 +60,41 @@
|
|
60
60
|
|
61
61
|
|
62
62
|
|
63
|
+
今回該当する箇所のコードを抜粋します。
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
```HAML
|
68
|
+
|
69
|
+
.best-main
|
70
|
+
|
71
|
+
.best-main-text
|
72
|
+
|
73
|
+
ハード
|
74
|
+
|
75
|
+
= d.fields_for :hards, class:"hards-parent" do |m|
|
76
|
+
|
77
|
+
= m.text_field :category, placeholder: "category", type: "text", class:"hards-input-text", id: "hard_text"
|
78
|
+
|
79
|
+
= icon('far', 'plus-square', id: 'pulas-hard')
|
80
|
+
|
81
|
+
#add
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
以下は全体のコードです。
|
88
|
+
|
89
|
+
|
90
|
+
|
63
91
|
|
64
92
|
|
65
93
|
### 該当のソースコード
|
66
94
|
|
67
95
|
|
68
96
|
|
69
|
-
```H
|
97
|
+
```HAML
|
70
98
|
|
71
99
|
= render 'partial/sidebar'
|
72
100
|
|
1
脱字の修正をしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,7 +52,7 @@
|
|
52
52
|
|
53
53
|
とりあえずは1つの項目が追加できるようになっている状態です。
|
54
54
|
|
55
|
-
ですが追加した項目に入力した値が保存されません。
|
55
|
+
ですが追加した項目に入力した値は保存されますが、オリジナルの項目フォームには保存されません。
|
56
56
|
|
57
57
|
例えば、オリジナルに「iPad」と入力し、追加した項目に「iPhone」と入力したら、「iPhone」だけが保存されます。
|
58
58
|
|