質問編集履歴

6

文法修正

2021/02/19 12:14

投稿

Mason
Mason

スコア14

test CHANGED
File without changes
test CHANGED
@@ -278,7 +278,9 @@
278
278
 
279
279
  ```
280
280
 
281
+ ```
282
+
281
- ```orders/new.html.erb
283
+ orders/new.html.erb
282
284
 
283
285
  <br>
284
286
 
@@ -366,6 +368,10 @@
366
368
 
367
369
  ruby 2.6.3
368
370
 
371
+
372
+
373
+ orders/new.html.erbからorders/confirrm.html.erbへ飛び、選択したほうを表示したいです。
374
+
369
375
  ここにより詳細な情報を記載してください。
370
376
 
371
377
  ### 前提・実現したいこと

5

文法修正

2021/02/19 12:14

投稿

Mason
Mason

スコア14

test CHANGED
File without changes
test CHANGED
@@ -48,7 +48,9 @@
48
48
 
49
49
 
50
50
 
51
+ ```
52
+
51
- ```orders_controller.rb
53
+ orders_controller.rb
52
54
 
53
55
 
54
56
 
@@ -154,7 +156,7 @@
154
156
 
155
157
  ```
156
158
 
157
- orders/new.html.erb
159
+ orders/confirm.html.erb
158
160
 
159
161
 
160
162
 
@@ -276,7 +278,7 @@
276
278
 
277
279
  ```
278
280
 
279
- ```ここに言語を入力
281
+ ```orders/new.html.erb
280
282
 
281
283
  <br>
282
284
 

4

文法修正

2021/02/19 12:10

投稿

Mason
Mason

スコア14

test CHANGED
File without changes
test CHANGED
@@ -28,294 +28,388 @@
28
28
 
29
29
 
30
30
 
31
+ # binding.pry
32
+
33
+ # params[:payment][:address] = params[:payment][:address].to_i
34
+
35
+ @order = Order.new(order_params)
36
+
37
+ #↑ここで引っかかる
38
+
39
+ @order.save
40
+
41
+ end
42
+
43
+
44
+
31
45
  ```~~打ち消し線~~
32
46
 
33
47
  ### 該当のソースコード
34
48
 
35
49
 
36
50
 
51
+ ```orders_controller.rb
52
+
53
+
54
+
55
+
56
+
57
+ class Public::OrdersController < ApplicationController
58
+
59
+
60
+
61
+
62
+
63
+ def index
64
+
65
+ @customer = Customer.find(params[:id])
66
+
67
+ @customers = @customer.product
68
+
69
+ # @orders = Order.all
70
+
71
+ end
72
+
73
+
74
+
75
+ def new
76
+
77
+ @customer = current_customer
78
+
79
+ # @i = current_customer.cart_items
80
+
81
+ @all = Product.all
82
+
83
+ @address = Address.all
84
+
85
+ end
86
+
87
+
88
+
89
+ def show
90
+
91
+ end
92
+
93
+
94
+
95
+ def create
96
+
97
+ @customer = current_customer
98
+
99
+ # binding.pry
100
+
101
+ # params[:payment][:address] = params[:payment][:address].to_i
102
+
103
+ @order = Order.new(order_params)
104
+
105
+ @order.save
106
+
107
+ end
108
+
109
+
110
+
111
+ def confirm
112
+
113
+ @cart_items = current_customer.cart_items
114
+
115
+ @total = 0
116
+
117
+ @order = Order.new(order_params)
118
+
119
+ # @order = Order.find(params[:id])
120
+
121
+
122
+
123
+ end
124
+
125
+
126
+
127
+ def complete
128
+
129
+ end
130
+
131
+
132
+
133
+ private
134
+
135
+
136
+
137
+ def order_params
138
+
139
+
140
+
141
+ params.permit(:payment, :address)
142
+
143
+
144
+
145
+ end
146
+
147
+
148
+
149
+
150
+
151
+ end
152
+
153
+
154
+
155
+ ```
156
+
157
+ orders/new.html.erb
158
+
159
+
160
+
161
+
162
+
163
+ ```<h3>注文情報確認</h3>
164
+
165
+ <br>
166
+
167
+ <br>
168
+
169
+ <div class="col-xs-8">
170
+
171
+ <table class="table table-hover">
172
+
173
+ <thead>
174
+
175
+ <tr>
176
+
177
+ <th>商品名</th>
178
+
179
+ <th>単価(税込)</th>
180
+
181
+ <th>数量</th>
182
+
183
+ <th>小計</th>
184
+
185
+ </tr>
186
+
187
+ </thead>
188
+
189
+ <tbody>
190
+
191
+ </table>
192
+
193
+
194
+
195
+ <% @total = 0 %>
196
+
197
+ <% @cart_items.each do |cart_item| %>
198
+
199
+ <td><%= attachment_image_tag @priduct, :image_id, size: "90x90", fallback: "cake.jpg" %>
200
+
201
+ <%= cart_item.product.name %>
202
+
203
+ <%= cart_item.product.price %>
204
+
205
+
206
+
207
+ <% @total += cart_item.product.price %>
208
+
209
+ <% end %>
210
+
211
+
212
+
213
+
214
+
215
+ <th>送料</th>
216
+
217
+ <th>800</th>
218
+
219
+ </tr>
220
+
221
+ <tr>
222
+
223
+ <th>商品合計</th>
224
+
225
+ <td><%= @total %></td>
226
+
227
+ </tr>
228
+
229
+ <tr>
230
+
231
+ <th>請求額</th>
232
+
233
+ <td><%= @total + 800 %></td>
234
+
235
+ </tr>
236
+
237
+
238
+
239
+
240
+
241
+ <br>
242
+
243
+ <br>
244
+
245
+ <br>
246
+
247
+ <h4>支払い方法</h4>
248
+
249
+ <%= @order.payment %>
250
+
251
+
252
+
253
+
254
+
255
+ <h4>お届け先</h4>
256
+
257
+ <%= @order.post_address %><%= @order.street_address %><br>
258
+
259
+ <%= @order.address %><br>
260
+
261
+
262
+
263
+ <div class="text-center">
264
+
265
+ <%= link_to "注文を確定する", orders_complete_path, class: 'btn btn-success' %>
266
+
267
+ </div>
268
+
269
+
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+ ```
278
+
279
+ ```ここに言語を入力
280
+
281
+ <br>
282
+
283
+ <h3 style="margin-left: 200px;">注文情報入力</h3><br>
284
+
285
+ <%= form_with(model: @orders, local: true, url: orders_path, method: :post) do |f| %>
286
+
287
+ <label style="margin-left: 130px;"><h4>支払い方法</h4></label><br>
288
+
289
+ <label style="margin-left: 190px;"><%= f.radio_button :payment, 0, checked: "checked"%> クレジットカード</label><br>
290
+
291
+ <label style="margin-left: 190px;"><%= f.radio_button :payment, 1 %> 銀行振込</label><br>
292
+
293
+ <br>
294
+
295
+ <label style="margin-left: 130px;"><h4>お届け先</h4></label><br>
296
+
297
+ <label style="margin-left: 190px;"><%= f.radio_button :address,1,checked: "checked" %> ご自身の住所</label>
298
+
299
+ <div><label style="margin-left: 220px;">
300
+
301
+ <%= current_customer.post_number %> <%= current_customer.street_address %>
302
+
303
+ <br>
304
+
305
+ <%= current_customer.last_name %><%= current_customer.first_name %></label>
306
+
307
+ <div>
308
+
309
+ <label style="margin-left:190px;"><%= f.radio_button :address ,2%> 登録済住所から選択</label><br>
310
+
311
+ <div><label style="margin-left: 220px;">
312
+
313
+ <%= f.collection_select(:address, current_customer.addresses.all, :post_address, :street_address)%>
314
+
315
+
316
+
317
+ <br>
318
+
319
+ </div>
320
+
321
+ <label style="margin-left: 190px;">
322
+
323
+ <%= f.radio_button :address,3 %> 新しいお届け先</label>
324
+
325
+ <div style="display: flex; margin-left:15% ;">
326
+
327
+ <div style="display: flex flex-direction: column; flex-wrap: wrap; width: 180px;">
328
+
329
+ <%= f.label :"郵便番号(ハイフンなし)"%><br><br>
330
+
331
+ <%= f.label :"住 所"%><br><br>
332
+
333
+ <%= f.label :"宛 名"%><br><br>
334
+
335
+ </div>
336
+
337
+ <div style=" margin-left:20px; ">
338
+
339
+ <%= f.text_field :postal_code %><br><br>
340
+
341
+ <%= f.text_field :shipping_address ,size: "60" %><br><br>
342
+
343
+ <%= f.text_field :name %><br><br>
344
+
345
+ <%= f.submit "確認画面へ進む", class: 'btn btn-primary' %>
346
+
347
+ <% end %>
348
+
349
+ ```
350
+
351
+ ### 試したこと
352
+
353
+
354
+
355
+ to_iが必要かと思われるのでコントローラーで記述してみました。
356
+
357
+
358
+
359
+
360
+
361
+ ### 補足情報(FW/ツールのバージョンなど)
362
+
363
+ Rails 5.2.4.5
364
+
365
+ ruby 2.6.3
366
+
367
+ ここにより詳細な情報を記載してください。
368
+
369
+ ### 前提・実現したいこと
370
+
371
+
372
+
373
+ ここに質問の内容を詳しく書いてください。
374
+
375
+ (例)PHP(CakePHP)で●●なシステムを作っています。
376
+
377
+ ■■な機能を実装中に以下のエラーメッセージが発生しました。
378
+
379
+
380
+
381
+ ### 発生している問題・エラーメッセージ
382
+
383
+
384
+
385
+ ```
386
+
387
+
388
+
389
+ ```
390
+
391
+
392
+
393
+ ### 該当のソースコード 
394
+
395
+ '0' is not a valid paymentエラー
396
+
37
397
  ```ここに言語名を入力
38
398
 
39
- class Public::OrdersController < ApplicationController
399
+
40
-
41
-
42
-
43
-
44
-
45
- def index
400
+
46
-
47
- @customer = Customer.find(params[:id])
401
+
48
-
49
- @customers = @customer.product
50
-
51
- # @orders = Order.all
52
-
53
- end
54
-
55
-
56
-
57
- def new
58
-
59
- @customer = current_customer
60
-
61
- # @i = current_customer.cart_items
62
-
63
- @all = Product.all
64
-
65
- @address = Address.all
66
-
67
- end
68
-
69
-
70
-
71
- def show
72
-
73
- end
74
-
75
-
76
-
77
- def create
78
-
79
- @customer = current_customer
80
-
81
- # binding.pry
82
-
83
- # params[:payment][:address] = params[:payment][:address].to_i
84
-
85
- @order = Order.new(order_params)
86
-
87
- @order.save
88
-
89
- end
90
-
91
-
92
-
93
- def confirm
94
-
95
- @cart_items = current_customer.cart_items
96
-
97
- @total = 0
98
-
99
- @order = Order.new(order_params)
100
-
101
- # @order = Order.find(params[:id])
102
-
103
-
104
-
105
- end
106
-
107
-
108
-
109
- def complete
110
-
111
- end
112
-
113
-
114
-
115
- private
116
-
117
-
118
-
119
- def order_params
120
-
121
-
122
-
123
- params.permit(:payment, :address)
124
-
125
-
126
-
127
- end
128
-
129
-
130
-
131
-
132
-
133
- end
134
-
135
-
136
-
137
- ```
138
-
139
- ### 該当のソースコード
140
-
141
- <h3>注文情報確認</h3>
142
-
143
- <br>
144
-
145
- <br>
146
-
147
- <div class="col-xs-8">
148
-
149
- <table class="table table-hover">
150
-
151
- <thead>
152
-
153
- <tr>
154
-
155
- <th>商品名</th>
156
-
157
- <th>単価(税込)</th>
158
-
159
- <th>数量</th>
160
-
161
- <th>小計</th>
162
-
163
- </tr>
164
-
165
- </thead>
166
-
167
- <tbody>
168
-
169
- </table>
170
-
171
-
172
-
173
- <% @total = 0 %>
174
-
175
- <% @cart_items.each do |cart_item| %>
176
-
177
- <td><%= attachment_image_tag @priduct, :image_id, size: "90x90", fallback: "cake.jpg" %>
178
-
179
- <%= cart_item.product.name %>
180
-
181
- <%= cart_item.product.price %>
182
-
183
-
184
-
185
- <% @total += cart_item.product.price %>
186
-
187
- <% end %>
188
-
189
-
190
-
191
-
192
-
193
- <th>送料</th>
194
-
195
- <th>800</th>
196
-
197
- </tr>
198
-
199
- <tr>
200
-
201
- <th>商品合計</th>
202
-
203
- <td><%= @total %></td>
204
-
205
- </tr>
206
-
207
- <tr>
208
-
209
- <th>請求額</th>
210
-
211
- <td><%= @total + 800 %></td>
212
-
213
- </tr>
214
-
215
-
216
-
217
-
218
-
219
- <br>
220
-
221
- <br>
222
-
223
- <br>
224
-
225
- <h4>支払い方法</h4>
226
-
227
- <%= @order.payment %>
228
-
229
-
230
-
231
-
232
-
233
- <h4>お届け先</h4>
234
-
235
- <%= @order.post_address %><%= @order.street_address %><br>
236
-
237
- <%= @order.address %><br>
238
-
239
-
240
-
241
- <div class="text-center">
242
-
243
- <%= link_to "注文を確定する", orders_complete_path, class: 'btn btn-success' %>
244
-
245
- </div>
246
-
247
-
248
-
249
-
250
-
251
-
252
-
253
-
254
-
255
- ```
256
402
 
257
403
  ### 試したこと
258
404
 
259
405
 
260
406
 
261
- to_iが必要か思われるのでコントローラーでしてみました
407
+ ここに問題に対して試したこしてください
262
-
263
-
264
408
 
265
409
 
266
410
 
267
411
  ### 補足情報(FW/ツールのバージョンなど)
268
412
 
269
- Rails 5.2.4.5
413
+
270
-
271
- ruby 2.6.3
272
414
 
273
415
  ここにより詳細な情報を記載してください。
274
-
275
- ### 前提・実現したいこと
276
-
277
-
278
-
279
- ここに質問の内容を詳しく書いてください。
280
-
281
- (例)PHP(CakePHP)で●●なシステムを作っています。
282
-
283
- ■■な機能を実装中に以下のエラーメッセージが発生しました。
284
-
285
-
286
-
287
- ### 発生している問題・エラーメッセージ
288
-
289
-
290
-
291
- ```
292
-
293
-
294
-
295
- ```
296
-
297
-
298
-
299
- ### 該当のソースコード 
300
-
301
- '0' is not a valid paymentエラー
302
-
303
- ```ここに言語名を入力
304
-
305
-
306
-
307
-
308
-
309
- ### 試したこと
310
-
311
-
312
-
313
- ここに問題に対して試したことを記載してください。
314
-
315
-
316
-
317
- ### 補足情報(FW/ツールのバージョンなど)
318
-
319
-
320
-
321
- ここにより詳細な情報を記載してください。

3

初心者マーク追加

2021/02/19 12:04

投稿

Mason
Mason

スコア14

test CHANGED
File without changes
test CHANGED
@@ -296,7 +296,7 @@
296
296
 
297
297
 
298
298
 
299
- ### 該当のソースコード
299
+ ### 該当のソースコード 
300
300
 
301
301
  '0' is not a valid paymentエラー
302
302
 

2

文法修正

2021/02/19 11:42

投稿

Mason
Mason

スコア14

test CHANGED
File without changes
test CHANGED
File without changes

1

文法修正

2021/02/19 11:40

投稿

Mason
Mason

スコア14

test CHANGED
File without changes
test CHANGED
@@ -12,21 +12,23 @@
12
12
 
13
13
  「0」が有効ではないので変換する記述方法がわからずにいます。
14
14
 
15
-
15
+ ご教授頂けると幸いです。
16
16
 
17
17
 
18
18
 
19
19
  ### 発生している問題・エラーメッセージ
20
20
 
21
+
22
+
23
+ ```
24
+
21
25
  ArgumentError in Public::OrdersController#create
22
26
 
23
- ```
24
-
25
- エラーメッセージ
26
-
27
- ```'0' is not a valid payment
27
+ '0' is not a valid payment
28
+
29
+
30
+
28
-
31
+ ```~~打ち消し線~~
29
-
30
32
 
31
33
  ### 該当のソースコード
32
34
 
@@ -134,7 +136,123 @@
134
136
 
135
137
  ```
136
138
 
137
-
139
+ ### 該当のソースコード
140
+
141
+ <h3>注文情報確認</h3>
142
+
143
+ <br>
144
+
145
+ <br>
146
+
147
+ <div class="col-xs-8">
148
+
149
+ <table class="table table-hover">
150
+
151
+ <thead>
152
+
153
+ <tr>
154
+
155
+ <th>商品名</th>
156
+
157
+ <th>単価(税込)</th>
158
+
159
+ <th>数量</th>
160
+
161
+ <th>小計</th>
162
+
163
+ </tr>
164
+
165
+ </thead>
166
+
167
+ <tbody>
168
+
169
+ </table>
170
+
171
+
172
+
173
+ <% @total = 0 %>
174
+
175
+ <% @cart_items.each do |cart_item| %>
176
+
177
+ <td><%= attachment_image_tag @priduct, :image_id, size: "90x90", fallback: "cake.jpg" %>
178
+
179
+ <%= cart_item.product.name %>
180
+
181
+ <%= cart_item.product.price %>
182
+
183
+
184
+
185
+ <% @total += cart_item.product.price %>
186
+
187
+ <% end %>
188
+
189
+
190
+
191
+
192
+
193
+ <th>送料</th>
194
+
195
+ <th>800</th>
196
+
197
+ </tr>
198
+
199
+ <tr>
200
+
201
+ <th>商品合計</th>
202
+
203
+ <td><%= @total %></td>
204
+
205
+ </tr>
206
+
207
+ <tr>
208
+
209
+ <th>請求額</th>
210
+
211
+ <td><%= @total + 800 %></td>
212
+
213
+ </tr>
214
+
215
+
216
+
217
+
218
+
219
+ <br>
220
+
221
+ <br>
222
+
223
+ <br>
224
+
225
+ <h4>支払い方法</h4>
226
+
227
+ <%= @order.payment %>
228
+
229
+
230
+
231
+
232
+
233
+ <h4>お届け先</h4>
234
+
235
+ <%= @order.post_address %><%= @order.street_address %><br>
236
+
237
+ <%= @order.address %><br>
238
+
239
+
240
+
241
+ <div class="text-center">
242
+
243
+ <%= link_to "注文を確定する", orders_complete_path, class: 'btn btn-success' %>
244
+
245
+ </div>
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+ ```
138
256
 
139
257
  ### 試したこと
140
258
 
@@ -184,121 +302,7 @@
184
302
 
185
303
  ```ここに言語名を入力
186
304
 
187
- <h3>注文情報確認</h3>
305
+
188
-
189
- <br>
190
-
191
- <br>
192
-
193
- <div class="col-xs-8">
194
-
195
- <table class="table table-hover">
196
-
197
- <thead>
198
-
199
- <tr>
200
-
201
- <th>商品名</th>
202
-
203
- <th>単価(税込)</th>
204
-
205
- <th>数量</th>
206
-
207
- <th>小計</th>
208
-
209
- </tr>
210
-
211
- </thead>
212
-
213
- <tbody>
214
-
215
- </table>
216
-
217
-
218
-
219
- <% @total = 0 %>
220
-
221
- <% @cart_items.each do |cart_item| %>
222
-
223
- <td><%= attachment_image_tag @priduct, :image_id, size: "90x90", fallback: "cake.jpg" %>
224
-
225
- <%= cart_item.product.name %>
226
-
227
- <%= cart_item.product.price %>
228
-
229
-
230
-
231
- <% @total += cart_item.product.price %>
232
-
233
- <% end %>
234
-
235
-
236
-
237
-
238
-
239
- <th>送料</th>
240
-
241
- <th>800</th>
242
-
243
- </tr>
244
-
245
- <tr>
246
-
247
- <th>商品合計</th>
248
-
249
- <td><%= @total %></td>
250
-
251
- </tr>
252
-
253
- <tr>
254
-
255
- <th>請求額</th>
256
-
257
- <td><%= @total + 800 %></td>
258
-
259
- </tr>
260
-
261
-
262
-
263
-
264
-
265
- <br>
266
-
267
- <br>
268
-
269
- <br>
270
-
271
- <h4>支払い方法</h4>
272
-
273
- <%= @order.payment %>
274
-
275
-
276
-
277
-
278
-
279
- <h4>お届け先</h4>
280
-
281
- <%= @order.post_address %><%= @order.street_address %><br>
282
-
283
- <%= @order.address %><br>
284
-
285
-
286
-
287
- <div class="text-center">
288
-
289
- <%= link_to "注文を確定する", orders_complete_path, class: 'btn btn-success' %>
290
-
291
- </div>
292
-
293
-
294
-
295
-
296
-
297
-
298
-
299
-
300
-
301
- ```
302
306
 
303
307
 
304
308