回答編集履歴

3

加筆

2019/08/21 01:05

投稿

rhiroe
rhiroe

スコア2344

test CHANGED
@@ -11,3 +11,33 @@
11
11
  attribute :image_url, :string, array: true
12
12
 
13
13
  ```
14
+
15
+
16
+
17
+ ```rb
18
+
19
+ @product = current_user.products.build(product_params) do |product|
20
+
21
+ product.product_images.build(*image_params)
22
+
23
+ end
24
+
25
+
26
+
27
+ def product_params
28
+
29
+ params.require(:product).permit(%i[name description price quality delivery_origin delivery_status delivery_cost prep_days category_id])
30
+
31
+ end
32
+
33
+
34
+
35
+ def image_params
36
+
37
+ params.require(:product).permit(product_images_attributes: [:id, :image_url[]])
38
+
39
+ end
40
+
41
+ ```
42
+
43
+ 雰囲気で書いたんですけどこんな感じですかね...?

2

typo

2019/08/21 01:05

投稿

rhiroe
rhiroe

スコア2344

test CHANGED
@@ -8,6 +8,6 @@
8
8
 
9
9
  ```rb
10
10
 
11
- attrubute :image_url, :string, array: true
11
+ attribute :image_url, :string, array: true
12
12
 
13
13
  ```

1

修正

2019/08/20 08:59

投稿

rhiroe
rhiroe

スコア2344

test CHANGED
@@ -1,4 +1,4 @@
1
- 文字列の配列なので["str"]となっているだけのように見えますが、
1
+ 文字列の配列なので`["str"]`となっているだけのように見えますが、
2
2
 
3
3
  本当に`["` `"]`を取り除いてもいいのですか?
4
4