質問編集履歴
2
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,7 +32,7 @@
|
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
-
配列で送られてきたデータをテーブルに送信する方法をどなたか教えていただけませんでしょうか。
|
35
|
+
配列で送られてきたデータをテーブルに1つずつ(2つの商品があれば2レコード)送信する方法をどなたか教えていただけませんでしょうか。
|
36
36
|
|
37
37
|
|
38
38
|
|
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -158,7 +158,7 @@
|
|
158
158
|
|
159
159
|
|
160
160
|
|
161
|
-
def address_params
|
161
|
+
def address_params
|
162
162
|
|
163
163
|
params.require(:address).permit(:user_id, :last_name, :first_name, :furi_last_name, :furi_first_name, :postal_code, :prefecture, :address, :store, :how_to_pay, orders_attributes: [
|
164
164
|
|
@@ -169,3 +169,111 @@
|
|
169
169
|
end
|
170
170
|
|
171
171
|
```
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
```
|
176
|
+
|
177
|
+
(models/address.rb)
|
178
|
+
|
179
|
+
class Address < ApplicationRecord
|
180
|
+
|
181
|
+
has_many :orders
|
182
|
+
|
183
|
+
accepts_nested_attributes_for :orders
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
addressesテーブル(カラム)
|
190
|
+
|
191
|
+
id
|
192
|
+
|
193
|
+
user_id
|
194
|
+
|
195
|
+
last_name
|
196
|
+
|
197
|
+
first_name
|
198
|
+
|
199
|
+
furi_last_name
|
200
|
+
|
201
|
+
furi_first_name
|
202
|
+
|
203
|
+
postal_code
|
204
|
+
|
205
|
+
prefecture
|
206
|
+
|
207
|
+
address
|
208
|
+
|
209
|
+
store
|
210
|
+
|
211
|
+
how_to_pay
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
```
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
```
|
222
|
+
|
223
|
+
(models/order.rb)
|
224
|
+
|
225
|
+
class Order < ApplicationRecord
|
226
|
+
|
227
|
+
belongs_to :address
|
228
|
+
|
229
|
+
belongs_to :product
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
ordersテーブル(カラム)
|
236
|
+
|
237
|
+
id
|
238
|
+
|
239
|
+
product_id
|
240
|
+
|
241
|
+
quantity
|
242
|
+
|
243
|
+
address_id
|
244
|
+
|
245
|
+
```
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
```
|
250
|
+
|
251
|
+
(models/product.rb)※一部記載
|
252
|
+
|
253
|
+
class Product < ApplicationRecord
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
has_many :orders
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
productsテーブル(カラム)
|
266
|
+
|
267
|
+
id
|
268
|
+
|
269
|
+
name
|
270
|
+
|
271
|
+
price
|
272
|
+
|
273
|
+
count
|
274
|
+
|
275
|
+
comment
|
276
|
+
|
277
|
+
category
|
278
|
+
|
279
|
+
```
|