質問編集履歴

1

体裁の修正

2020/12/29 09:44

投稿

hrc
hrc

スコア55

test CHANGED
File without changes
test CHANGED
@@ -4,149 +4,193 @@
4
4
 
5
5
  下記のようなハッシュの
6
6
 
7
+ "thumbnail"の"id": "1013",
8
+
9
+ にあたるデータを抽出したいです。ハッシュのfindやselectでは出来なそうなので
10
+
11
+ どなたかご存じの方ご教示ください。
12
+
13
+
14
+
15
+ ※抽出用ハッシュ(一部)
16
+
17
+ ```Ruby
18
+
19
+ {
20
+
7
- "included": [
21
+ "data": [
8
22
 
9
23
  {
10
24
 
25
+ "id": "1192",
26
+
27
+ "type": "product",
28
+
29
+ "attributes": {
30
+
31
+ "id": 1192,
32
+
33
+ "number": "test_001",
34
+
35
+ "state": "active",
36
+
37
+ "human_state": "表示",
38
+
39
+ "name": "テスト",
40
+
41
+ "upsell_product_id": 1198,
42
+
43
+ "upsell_product_number": "upsell",
44
+
45
+ "upsell_product_name": "アップセル",
46
+
47
+ "cv_upsell_product_id": 1309,
48
+
49
+ "cv_upsell_product_number": "thanks_upsell",
50
+
51
+ "cv_upsell_product_name": "サンクスアップセル",
52
+
53
+ "maker_id": null,
54
+
55
+ "maker_name": null,
56
+
57
+ "description": "",
58
+
59
+ "description_mobile": "",
60
+
61
+ "sub_description": "",
62
+
63
+ "sub_description_mobile": "",
64
+
65
+ "meta_description": "",
66
+
67
+ "meta_keywords": "",
68
+
69
+ "is_recurring": true,
70
+
71
+ "product_category_names": "",
72
+
73
+ "master_list_price": 7500,
74
+
75
+ "master_sales_price": 2500,
76
+
77
+ "master_sku": "smart_teiki_002-001",
78
+
79
+ "created_at": "2019/09/30 14:55:00",
80
+
81
+ "updated_at": "2020/04/17 01:47:48",
82
+
83
+ "deleted_at": null
84
+
85
+ },
86
+
87
+ "relationships": {
88
+
89
+ "variants": {
90
+
91
+ "data": [
92
+
93
+ {
94
+
95
+ "id": "1723",
96
+
97
+ "type": "variant"
98
+
99
+ },
100
+
101
+ {
102
+
103
+ "id": "1722",
104
+
105
+ "type": "variant"
106
+
107
+ },
108
+
109
+ {
110
+
111
+ "id": "1721",
112
+
113
+ "type": "variant"
114
+
115
+ },
116
+
117
+ {
118
+
119
+ "id": "1720",
120
+
121
+ "type": "variant"
122
+
123
+ },
124
+
125
+ {
126
+
127
+ "id": "1589",
128
+
129
+ "type": "variant"
130
+
131
+ }
132
+
133
+ ]
134
+
135
+ },
136
+
137
+ "thumbnail": {
138
+
139
+ "data": {
140
+
141
+ "id": "1013",
142
+
143
+ "type": "thumbnail"
144
+
145
+ }
146
+
147
+ }
148
+
149
+ }
150
+
151
+ }
152
+
153
+ ],
154
+
155
+ "included": [
156
+
157
+ {
158
+
11
159
  "id": "1013",
12
160
 
13
- にあたるデータを抽出したいです。ハッシュのfindやselectでは出来なそうなので
14
-
15
- どなたかご存じの方ご教示ください。
16
-
17
-
18
-
19
- ※抽出用ハッシュ(一部)
20
-
21
- {
22
-
23
- "data": [
24
-
25
- {
26
-
27
- "id": "1192",
28
-
29
- "type": "product",
161
+ "type": "thumbnail",
30
162
 
31
163
  "attributes": {
32
164
 
33
- "id": 1192,
34
-
35
- "number": "test_001",
36
-
37
- "state": "active",
38
-
39
- "human_state": "表示",
40
-
41
- "name": "テスト",
42
-
43
- "upsell_product_id": 1198,
44
-
45
- "upsell_product_number": "upsell",
46
-
47
- "upsell_product_name": "アップセル",
48
-
49
- "cv_upsell_product_id": 1309,
50
-
51
- "cv_upsell_product_number": "thanks_upsell",
52
-
53
- "cv_upsell_product_name": "サンクスアップセル",
54
-
55
- "maker_id": null,
56
-
57
- "maker_name": null,
58
-
59
- "description": "",
60
-
61
- "description_mobile": "",
62
-
63
- "sub_description": "",
64
-
65
- "sub_description_mobile": "",
66
-
67
- "meta_description": "",
68
-
69
- "meta_keywords": "",
70
-
71
- "is_recurring": true,
72
-
73
- "product_category_names": "",
74
-
75
- "master_list_price": 7500,
76
-
77
- "master_sales_price": 2500,
78
-
79
- "master_sku": "smart_teiki_002-001",
80
-
81
- "created_at": "2019/09/30 14:55:00",
82
-
83
- "updated_at": "2020/04/17 01:47:48",
84
-
85
- "deleted_at": null
86
-
87
- },
88
-
89
- "relationships": {
90
-
91
- "variants": {
92
-
93
- "data": [
94
-
95
- {
96
-
97
- "id": "1723",
98
-
99
- "type": "variant"
100
-
101
- },
102
-
103
- {
104
-
105
- "id": "1722",
106
-
107
- "type": "variant"
108
-
109
- },
110
-
111
- {
112
-
113
- "id": "1721",
114
-
115
- "type": "variant"
116
-
117
- },
118
-
119
- {
120
-
121
- "id": "1720",
122
-
123
- "type": "variant"
124
-
125
- },
126
-
127
- {
128
-
129
- "id": "1589",
130
-
131
- "type": "variant"
132
-
133
- }
134
-
135
- ]
136
-
137
- },
138
-
139
- "thumbnail": {
140
-
141
- "data": {
142
-
143
- "id": "1013",
144
-
145
- "type": "thumbnail"
146
-
147
- }
148
-
149
- }
165
+ "id": 1013,
166
+
167
+ "file_name": "test.png",
168
+
169
+ "content_type": "image/png",
170
+
171
+ "file_size": 599789,
172
+
173
+ "position": 0,
174
+
175
+ "url": "https://example.com/28cd4d9bc4/ec_assets/original.png?1587703559",
176
+
177
+ "url_small": "https://example.com/28cd4d9bc4/ec_assets/small.png?1587703559",
178
+
179
+ "url_medium": "https://example.com/28cd4d9bc4/ec_assets/medium.png?1587703559",
180
+
181
+ "url_large": "https://example.com/28cd4d9bc4/ec_assets/large.png?1587703559",
182
+
183
+ "path": "/28cd4d9bc4/ec_assets/original.png",
184
+
185
+ "path_small": "/28cd4d9bc4/ec_assets/small.png",
186
+
187
+ "path_medium": "/28cd4d9bc4/ec_assets/medium.png",
188
+
189
+ "path_large": "/28cd4d9bc4/ec_assets/large.png",
190
+
191
+ "created_at": "2020/04/24 13:46:00",
192
+
193
+ "updated_at": "2020/04/24 13:46:00"
150
194
 
151
195
  }
152
196
 
@@ -154,44 +198,34 @@
154
198
 
155
199
  ],
156
200
 
157
- "included": [
158
-
159
- {
160
-
161
- "id": "1013",
162
-
163
- "type": "thumbnail",
164
-
165
- "attributes": {
201
+ "meta": {
202
+
166
-
203
+ "total_count": 1,
204
+
205
+ "page": 1,
206
+
167
- "id": 1013,
207
+ "per": 20,
168
-
169
- "file_name": "test.png",
208
+
170
-
171
- "content_type": "image/png",
172
-
173
- "file_size": 599789,
174
-
175
- "position": 0,
209
+ "count": 1,
210
+
176
-
211
+ "total_pages": 1
212
+
213
+ },
214
+
215
+ "links": {
216
+
177
- "url": "https://example.com/28cd4d9bc4/ec_assets/original.png?1587703559",
217
+ "self": "http://localhost:3000/api/v1/products?page=1&per=20",
218
+
178
-
219
+ "prev": null,
220
+
179
- "url_small": "https://example.com/28cd4d9bc4/ec_assets/small.png?1587703559",
221
+ "first": "http://localhost:3000/api/v1/products?page=1&per=1",
180
-
222
+
181
- "url_medium": "https://example.com/28cd4d9bc4/ec_assets/medium.png?1587703559",
223
+ "next": "http://localhost:3000/api/v1/products?page=&per=20",
182
-
224
+
183
- "url_large": "https://example.com/28cd4d9bc4/ec_assets/large.png?1587703559",
225
+ "last": "http://localhost:3000/api/v1/products?page=1&per=20"
184
-
185
- "path": "/28cd4d9bc4/ec_assets/original.png",
226
+
186
-
187
- "path_small": "/28cd4d9bc4/ec_assets/small.png",
188
-
189
- "path_medium": "/28cd4d9bc4/ec_assets/medium.png",
190
-
191
- "path_large": "/28cd4d9bc4/ec_assets/large.png",
192
-
193
- "created_at": "2020/04/24 13:46:00",
194
-
195
- "updated_at": "2020/04/24 13:46:00"
196
-
197
- }
227
+ }
228
+
229
+ }
230
+
231
+ ```