質問編集履歴

6

修正

2020/10/30 14:15

投稿

pico0120
pico0120

スコア2

test CHANGED
File without changes
test CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
 
24
24
 
25
- with_options presence: true do
25
+ with_options presence: true do
26
26
 
27
27
  validates :postal_code, format: {with: /\A[0-9]{3}-[0-9]{4}\z/, message: "is invalid. Include hyphen(-)"}
28
28
 

5

修正

2020/10/30 14:15

投稿

pico0120
pico0120

スコア2

test CHANGED
File without changes
test CHANGED
@@ -22,17 +22,17 @@
22
22
 
23
23
 
24
24
 
25
- with_options presence: true do
25
+ with_options presence: true do
26
26
 
27
27
  validates :postal_code, format: {with: /\A[0-9]{3}-[0-9]{4}\z/, message: "is invalid. Include hyphen(-)"}
28
28
 
29
29
  validates :city, format: { with: /\A[ぁ-んァ-ン一-龥]/, message: "is invalid. Input full-width characters."}
30
30
 
31
- validates :address_num, format: {with: /\A[0-9]{3}-[0-9]{4}\z/, message: "is invalid. Include hyphen(-)"}
31
+ validates :address_num
32
-
33
- validates :building_name, format: { with: /\A[ぁ-んァ-ン一-龥]/, message: "is invalid. Input full-width characters."}
32
+
34
-
35
- validates :phone, format: {with: /\A[0-9]{3}-[0-9]{4}\z/, message: "is invalid. Include hyphen(-)"}
33
+ validates :phone, format: {with: /\A\d{10}\z|\A\d{11}\z/ , message: "is invalid."}
34
+
35
+ validates :token
36
36
 
37
37
  end
38
38
 

4

修正

2020/10/30 14:15

投稿

pico0120
pico0120

スコア2

test CHANGED
File without changes
test CHANGED
@@ -224,7 +224,7 @@
224
224
 
225
225
  以下、フォームから入力する画面のビューです。
226
226
 
227
- 住所情報ばadressesテーブル(postal_code, prefecture_id, city, address_num, building_name, phone, order_id)、購入情報はorders(user_id, item_id)テーブルに保存させようとしています。
227
+ 住所情報(postal_code, prefecture_id, city, address_num, building_name, phone, order_id)をadressesテーブル、購入情報(user_id, item_id)はordersテーブルに保存させようとしています。
228
228
 
229
229
  ```ruby
230
230
 

3

追記

2020/10/30 05:22

投稿

pico0120
pico0120

スコア2

test CHANGED
File without changes
test CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  include ActiveModel::Model
20
20
 
21
- attr_accessor :postal_code, :prefecture_id, :city, :address_num, :building_name, :phone, :order
21
+ attr_accessor :postal_code, :prefecture_id, :city, :address_num, :building_name, :phone, :item.id, :params[:token], :current_user.id
22
22
 
23
23
 
24
24
 
@@ -46,7 +46,9 @@
46
46
 
47
47
  Order.create(item:id)
48
48
 
49
- Address.create(postal_code: postal_code, address_num: address_num, building_name: building_name, phone: phone)
49
+ Address.create(postal_code: postal_code, address_num: address_num, building_name: building_name, phone: pOrder.create(user: current_user.id, item: id)
50
+
51
+ Address.create(postal_code: postal_code, prefecture_id: prefecture_id, city: city, address_num: address_num, building_name: building_name, phone: phone)hone)
50
52
 
51
53
  end
52
54
 
@@ -108,7 +110,7 @@
108
110
 
109
111
  def order_params
110
112
 
111
- params.require(:order_address).permit(:postal_code, :address_num, :building_name, :phone).merge(token: params[:token], user_id: current_user.id, item: id)
113
+ params.permit(:postal_code, :prefecture_id, :city, :address_num, :building_name, :phone, :item_id).merge(token: params[:token], user_id: current_user.id)
112
114
 
113
115
  end
114
116
 
@@ -220,6 +222,272 @@
220
222
 
221
223
 
222
224
 
225
+ 以下、フォームから入力する画面のビューです。
226
+
227
+ 住所情報ばadressesテーブル(postal_code, prefecture_id, city, address_num, building_name, phone, order_id)、購入情報はorders(user_id, item_id)テーブルに保存させようとしています。
228
+
229
+ ```ruby
230
+
231
+ <div class='transaction-contents'>
232
+
233
+ <div class='transaction-main'>
234
+
235
+ <h1 class='transaction-title-text'>
236
+
237
+ 購入内容の確認
238
+
239
+ </h1>
240
+
241
+ <%# 購入内容の表示 %>
242
+
243
+ <div class='buy-item-info'>
244
+
245
+ <%= image_tag "item-sample.png", class: 'buy-item-img' %>
246
+
247
+ <div class='buy-item-right-content'>
248
+
249
+ <h2 class='buy-item-text'>
250
+
251
+ <%= "商品名" %>
252
+
253
+ </h2>
254
+
255
+ <div class='buy-item-price'>
256
+
257
+ <p class='item-price-text'>¥<%= "999,999,999" %></p>
258
+
259
+ <p class='item-price-sub-text'>(税込)送料込み</p>
260
+
261
+ </div>
262
+
263
+ </div>
264
+
265
+ </div>
266
+
267
+ <%# /購入内容の表示 %>
268
+
269
+
270
+
271
+ <%# 支払額の表示 %>
272
+
273
+ <div class='item-payment'>
274
+
275
+ <h1 class='item-payment-title'>
276
+
277
+ 支払金額
278
+
279
+ </h1>
280
+
281
+ <p class='item-payment-price'>
282
+
283
+ ¥<%= "販売価格" %>
284
+
285
+ </p>
286
+
287
+ </div>
288
+
289
+ <%# /支払額の表示 %>
290
+
291
+
292
+
293
+ <%= form_with(model: @order_address, url: item_orders_path, id: 'charge-form', class: 'transaction-form-wrap',local: true) do |f| %>
294
+
295
+ <%# カード情報の入力 %>
296
+
297
+ <div class='credit-card-form'>
298
+
299
+ <h1 class='info-input-haedline'>
300
+
301
+ クレジットカード情報入力
302
+
303
+ </h1>
304
+
305
+ <div class="form-group">
306
+
307
+ <div class='form-text-wrap'>
308
+
309
+ <label class="form-text">カード情報</label>
310
+
311
+ <span class="indispensable">必須</span>
312
+
313
+ </div>
314
+
315
+ <%= f.text_field :number, class:"input-default", id:"card-number", placeholder:"カード番号(半角英数字)", maxlength:"16" %>
316
+
317
+ <div class='available-card'>
318
+
319
+ <%= image_tag 'card-visa.gif', class: 'card-logo'%>
320
+
321
+ <%= image_tag 'card-mastercard.gif', class: 'card-logo'%>
322
+
323
+ <%= image_tag 'card-jcb.gif', class: 'card-logo'%>
324
+
325
+ <%= image_tag 'card-amex.gif', class: 'card-logo'%>
326
+
327
+ </div>
328
+
329
+ </div>
330
+
331
+ <div class="form-group">
332
+
333
+ <div class='form-text-wrap'>
334
+
335
+ <label class="form-text">有効期限</label>
336
+
337
+ <span class="indispensable">必須</span>
338
+
339
+ </div>
340
+
341
+ <div class='input-expiration-date-wrap'>
342
+
343
+ <%= f.text_area :exp_month, class:"input-expiration-date", id:"card-exp-month", placeholder:"例)3" %>
344
+
345
+ <p>月</p>
346
+
347
+ <%= f.text_area :exp_year, class:"input-expiration-date", id:"card-exp-year", placeholder:"例)23" %>
348
+
349
+ <p>年</p>
350
+
351
+ </div>
352
+
353
+ </div>
354
+
355
+ <div class="form-group">
356
+
357
+ <div class='form-text-wrap'>
358
+
359
+ <label class="form-text">セキュリティコード</label>
360
+
361
+ <span class="indispensable">必須</span>
362
+
363
+ </div>
364
+
365
+ <%= f.text_field :cvc,class:"input-default", id:"card-cvc", placeholder:"カード背面4桁もしくは3桁の番号", maxlength:"4" %>
366
+
367
+ </div>
368
+
369
+ </div>
370
+
371
+ <%# /カード情報の入力 %>
372
+
373
+
374
+
375
+ <%# 配送先の入力 %>
376
+
377
+ <div class='shipping-address-form'>
378
+
379
+ <h1 class='info-input-haedline'>
380
+
381
+ 配送先入力
382
+
383
+ </h1>
384
+
385
+ <div class="form-group">
386
+
387
+ <div class='form-text-wrap'>
388
+
389
+ <label class="form-text">郵便番号</label>
390
+
391
+ <span class="indispensable">必須</span>
392
+
393
+ </div>
394
+
395
+ <%= f.text_field :postal_code, class:"input-default", id:"postal-code", placeholder:"例)123-4567", maxlength:"8" %>
396
+
397
+ </div>
398
+
399
+ <div class="form-group">
400
+
401
+ <div class='form-text-wrap'>
402
+
403
+ <label class="form-text">都道府県</label>
404
+
405
+ <span class="indispensable">必須</span>
406
+
407
+ </div>
408
+
409
+ <%= f.collection_select(:prefecture_id, Prefecture.all, :id, :name, {}, {class:"select-box", id:"prefecture"}) %>
410
+
411
+ </div>
412
+
413
+ <div class="form-group">
414
+
415
+ <div class='form-text-wrap'>
416
+
417
+ <label class="form-text">市区町村</label>
418
+
419
+ <span class="indispensable">必須</span>
420
+
421
+ </div>
422
+
423
+ <%= f.text_field :city, class:"input-default", id:"city", placeholder:"例)横浜市緑区"%>
424
+
425
+ </div>
426
+
427
+ <div class="form-group">
428
+
429
+ <div class='form-text-wrap'>
430
+
431
+ <label class="form-text">番地</label>
432
+
433
+ <span class="indispensable">必須</span>
434
+
435
+ </div>
436
+
437
+ <%= f.text_field :address_num, class:"input-default", id:"addresses", placeholder:"例)青山1-1-1"%>
438
+
439
+ </div>
440
+
441
+ <div class="form-group">
442
+
443
+ <div class='form-text-wrap'>
444
+
445
+ <label class="form-text">建物名</label>
446
+
447
+ <span class="form-any">任意</span>
448
+
449
+ </div>
450
+
451
+ <%= f.text_field :building_name, class:"input-default", id:"building", placeholder:"例)柳ビル103"%>
452
+
453
+ </div>
454
+
455
+ <div class="form-group">
456
+
457
+ <div class='form-text-wrap'>
458
+
459
+ <label class="form-text">電話番号</label>
460
+
461
+ <span class="indispensable">必須</span>
462
+
463
+ </div>
464
+
465
+ <%= f.text_field :phone, class:"input-default", id:"phone-number", placeholder:"例)09012345678",maxlength:"11"%>
466
+
467
+ </div>
468
+
469
+ </div>
470
+
471
+ <%# /配送先の入力 %>
472
+
473
+ <div class='buy-btn'>
474
+
475
+ <%= f.submit "購入" ,class:"buy-red-btn" %>
476
+
477
+ </div>
478
+
479
+ <% end %>
480
+
481
+ </div>
482
+
483
+ </div>
484
+
485
+ ```
486
+
487
+
488
+
489
+
490
+
223
491
  大変恐縮ですが、何が問題かご教授いただけませんでしょうか。
224
492
 
225
493
  超初心者のため謎コードが多いかもしれませんが、どうぞよろしくお願いいたします。

2

コードの誤字脱字修正

2020/10/30 05:20

投稿

pico0120
pico0120

スコア2

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- 自分では以下のように考えましたが、この記述では、"param is missing or the value is empty: order"というエラーが出てうまく情報を渡すことができません。
7
+ 自分では以下のように考えましたが、この記述では、"param is missing or the value is empty: order_address"というエラーが出てうまく情報を渡すことができません。
8
8
 
9
9
 
10
10
 
@@ -46,7 +46,7 @@
46
46
 
47
47
  Order.create(item:id)
48
48
 
49
- Address.create(pstal_code: postal_code, address_num: address_num, building_name: building_name, phone: phone)
49
+ Address.create(postal_code: postal_code, address_num: address_num, building_name: building_name, phone: phone)
50
50
 
51
51
  end
52
52
 
@@ -108,7 +108,7 @@
108
108
 
109
109
  def order_params
110
110
 
111
- params.require(:order).permit(:id).merge(token: params[:token])
111
+ params.require(:order_address).permit(:postal_code, :address_num, :building_name, :phone).merge(token: params[:token], user_id: current_user.id, item: id)
112
112
 
113
113
  end
114
114
 

1

各コードのファイル名追記しました。

2020/10/29 09:21

投稿

pico0120
pico0120

スコア2

test CHANGED
File without changes
test CHANGED
@@ -8,9 +8,9 @@
8
8
 
9
9
 
10
10
 
11
- Formオブジェクトで、まず order_address.rbの中で、フォームからパラメーターとして送られてきた情報をテーブルに保存する。
11
+ Formオブジェクトで、まずフォームからパラメーターとして送られてきた情報をテーブルに保存する。
12
+
12
-
13
+ order_address.rb
13
-
14
14
 
15
15
  ```ruby
16
16
 
@@ -60,7 +60,9 @@
60
60
 
61
61
  ```
62
62
 
63
- 次に、orders_controller.rbのnewアクション、createアクションでFormオブジェクトのインスタンスを生成するようにする。
63
+ 次に、コントローラーのnewアクション、createアクションでFormオブジェクトのインスタンスを生成するようにする。
64
+
65
+ orders_controller.rb
64
66
 
65
67
  ```ruby
66
68
 
@@ -138,6 +140,8 @@
138
140
 
139
141
  (PAY.JPでクレジットカード決済機能もつけています。)
140
142
 
143
+ card.js
144
+
141
145
  ```ruby
142
146
 
143
147