teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

6

修正

2020/10/30 14:15

投稿

pico0120
pico0120

スコア2

title CHANGED
File without changes
body CHANGED
@@ -10,7 +10,7 @@
10
10
  include ActiveModel::Model
11
11
  attr_accessor :postal_code, :prefecture_id, :city, :address_num, :building_name, :phone, :item.id, :params[:token], :current_user.id
12
12
 
13
- with_options presence: true do
13
+ with_options presence: true do
14
14
  validates :postal_code, format: {with: /\A[0-9]{3}-[0-9]{4}\z/, message: "is invalid. Include hyphen(-)"}
15
15
  validates :city, format: { with: /\A[ぁ-んァ-ン一-龥]/, message: "is invalid. Input full-width characters."}
16
16
  validates :address_num

5

修正

2020/10/30 14:15

投稿

pico0120
pico0120

スコア2

title CHANGED
File without changes
body CHANGED
@@ -10,12 +10,12 @@
10
10
  include ActiveModel::Model
11
11
  attr_accessor :postal_code, :prefecture_id, :city, :address_num, :building_name, :phone, :item.id, :params[:token], :current_user.id
12
12
 
13
- with_options presence: true do
13
+ with_options presence: true do
14
14
  validates :postal_code, format: {with: /\A[0-9]{3}-[0-9]{4}\z/, message: "is invalid. Include hyphen(-)"}
15
15
  validates :city, format: { with: /\A[ぁ-んァ-ン一-龥]/, message: "is invalid. Input full-width characters."}
16
- validates :address_num, format: {with: /\A[0-9]{3}-[0-9]{4}\z/, message: "is invalid. Include hyphen(-)"}
16
+ validates :address_num
17
- validates :building_name, format: { with: /\A[ぁ-んァ-ン一-龥]/, message: "is invalid. Input full-width characters."}
18
- validates :phone, format: {with: /\A[0-9]{3}-[0-9]{4}\z/, message: "is invalid. Include hyphen(-)"}
17
+ validates :phone, format: {with: /\A\d{10}\z|\A\d{11}\z/ , message: "is invalid."}
18
+ validates :token
19
19
  end
20
20
  validates :prefecture_id, numericality: { other_than: 0, message: "can't be blank" }
21
21
 

4

修正

2020/10/30 14:15

投稿

pico0120
pico0120

スコア2

title CHANGED
File without changes
body CHANGED
@@ -111,7 +111,7 @@
111
111
  ```
112
112
 
113
113
  以下、フォームから入力する画面のビューです。
114
- 住所情報ばadressesテーブル(postal_code, prefecture_id, city, address_num, building_name, phone, order_id)、購入情報はorders(user_id, item_id)テーブルに保存させようとしています。
114
+ 住所情報(postal_code, prefecture_id, city, address_num, building_name, phone, order_id)をadressesテーブル、購入情報(user_id, item_id)はordersテーブルに保存させようとしています。
115
115
  ```ruby
116
116
  <div class='transaction-contents'>
117
117
  <div class='transaction-main'>

3

追記

2020/10/30 05:22

投稿

pico0120
pico0120

スコア2

title CHANGED
File without changes
body CHANGED
@@ -8,7 +8,7 @@
8
8
  ```ruby
9
9
  class OrderAddress
10
10
  include ActiveModel::Model
11
- attr_accessor :postal_code, :prefecture_id, :city, :address_num, :building_name, :phone, :order
11
+ attr_accessor :postal_code, :prefecture_id, :city, :address_num, :building_name, :phone, :item.id, :params[:token], :current_user.id
12
12
 
13
13
  with_options presence: true do
14
14
  validates :postal_code, format: {with: /\A[0-9]{3}-[0-9]{4}\z/, message: "is invalid. Include hyphen(-)"}
@@ -22,7 +22,8 @@
22
22
 
23
23
  def save
24
24
  Order.create(item:id)
25
- Address.create(postal_code: postal_code, address_num: address_num, building_name: building_name, phone: phone)
25
+ Address.create(postal_code: postal_code, address_num: address_num, building_name: building_name, phone: pOrder.create(user: current_user.id, item: id)
26
+ Address.create(postal_code: postal_code, prefecture_id: prefecture_id, city: city, address_num: address_num, building_name: building_name, phone: phone)hone)
26
27
  end
27
28
  end
28
29
 
@@ -53,7 +54,7 @@
53
54
 
54
55
  private
55
56
  def order_params
56
- params.require(:order_address).permit(:postal_code, :address_num, :building_name, :phone).merge(token: params[:token], user_id: current_user.id, item: id)
57
+ params.permit(:postal_code, :prefecture_id, :city, :address_num, :building_name, :phone, :item_id).merge(token: params[:token], user_id: current_user.id)
57
58
  end
58
59
 
59
60
  def pay_item
@@ -109,5 +110,138 @@
109
110
  window.addEventListener("load",pay);
110
111
  ```
111
112
 
113
+ 以下、フォームから入力する画面のビューです。
114
+ 住所情報ばadressesテーブル(postal_code, prefecture_id, city, address_num, building_name, phone, order_id)、購入情報はorders(user_id, item_id)テーブルに保存させようとしています。
115
+ ```ruby
116
+ <div class='transaction-contents'>
117
+ <div class='transaction-main'>
118
+ <h1 class='transaction-title-text'>
119
+ 購入内容の確認
120
+ </h1>
121
+ <%# 購入内容の表示 %>
122
+ <div class='buy-item-info'>
123
+ <%= image_tag "item-sample.png", class: 'buy-item-img' %>
124
+ <div class='buy-item-right-content'>
125
+ <h2 class='buy-item-text'>
126
+ <%= "商品名" %>
127
+ </h2>
128
+ <div class='buy-item-price'>
129
+ <p class='item-price-text'>¥<%= "999,999,999" %></p>
130
+ <p class='item-price-sub-text'>(税込)送料込み</p>
131
+ </div>
132
+ </div>
133
+ </div>
134
+ <%# /購入内容の表示 %>
135
+
136
+ <%# 支払額の表示 %>
137
+ <div class='item-payment'>
138
+ <h1 class='item-payment-title'>
139
+ 支払金額
140
+ </h1>
141
+ <p class='item-payment-price'>
142
+ ¥<%= "販売価格" %>
143
+ </p>
144
+ </div>
145
+ <%# /支払額の表示 %>
146
+
147
+ <%= form_with(model: @order_address, url: item_orders_path, id: 'charge-form', class: 'transaction-form-wrap',local: true) do |f| %>
148
+ <%# カード情報の入力 %>
149
+ <div class='credit-card-form'>
150
+ <h1 class='info-input-haedline'>
151
+ クレジットカード情報入力
152
+ </h1>
153
+ <div class="form-group">
154
+ <div class='form-text-wrap'>
155
+ <label class="form-text">カード情報</label>
156
+ <span class="indispensable">必須</span>
157
+ </div>
158
+ <%= f.text_field :number, class:"input-default", id:"card-number", placeholder:"カード番号(半角英数字)", maxlength:"16" %>
159
+ <div class='available-card'>
160
+ <%= image_tag 'card-visa.gif', class: 'card-logo'%>
161
+ <%= image_tag 'card-mastercard.gif', class: 'card-logo'%>
162
+ <%= image_tag 'card-jcb.gif', class: 'card-logo'%>
163
+ <%= image_tag 'card-amex.gif', class: 'card-logo'%>
164
+ </div>
165
+ </div>
166
+ <div class="form-group">
167
+ <div class='form-text-wrap'>
168
+ <label class="form-text">有効期限</label>
169
+ <span class="indispensable">必須</span>
170
+ </div>
171
+ <div class='input-expiration-date-wrap'>
172
+ <%= f.text_area :exp_month, class:"input-expiration-date", id:"card-exp-month", placeholder:"例)3" %>
173
+ <p>月</p>
174
+ <%= f.text_area :exp_year, class:"input-expiration-date", id:"card-exp-year", placeholder:"例)23" %>
175
+ <p>年</p>
176
+ </div>
177
+ </div>
178
+ <div class="form-group">
179
+ <div class='form-text-wrap'>
180
+ <label class="form-text">セキュリティコード</label>
181
+ <span class="indispensable">必須</span>
182
+ </div>
183
+ <%= f.text_field :cvc,class:"input-default", id:"card-cvc", placeholder:"カード背面4桁もしくは3桁の番号", maxlength:"4" %>
184
+ </div>
185
+ </div>
186
+ <%# /カード情報の入力 %>
187
+
188
+ <%# 配送先の入力 %>
189
+ <div class='shipping-address-form'>
190
+ <h1 class='info-input-haedline'>
191
+ 配送先入力
192
+ </h1>
193
+ <div class="form-group">
194
+ <div class='form-text-wrap'>
195
+ <label class="form-text">郵便番号</label>
196
+ <span class="indispensable">必須</span>
197
+ </div>
198
+ <%= f.text_field :postal_code, class:"input-default", id:"postal-code", placeholder:"例)123-4567", maxlength:"8" %>
199
+ </div>
200
+ <div class="form-group">
201
+ <div class='form-text-wrap'>
202
+ <label class="form-text">都道府県</label>
203
+ <span class="indispensable">必須</span>
204
+ </div>
205
+ <%= f.collection_select(:prefecture_id, Prefecture.all, :id, :name, {}, {class:"select-box", id:"prefecture"}) %>
206
+ </div>
207
+ <div class="form-group">
208
+ <div class='form-text-wrap'>
209
+ <label class="form-text">市区町村</label>
210
+ <span class="indispensable">必須</span>
211
+ </div>
212
+ <%= f.text_field :city, class:"input-default", id:"city", placeholder:"例)横浜市緑区"%>
213
+ </div>
214
+ <div class="form-group">
215
+ <div class='form-text-wrap'>
216
+ <label class="form-text">番地</label>
217
+ <span class="indispensable">必須</span>
218
+ </div>
219
+ <%= f.text_field :address_num, class:"input-default", id:"addresses", placeholder:"例)青山1-1-1"%>
220
+ </div>
221
+ <div class="form-group">
222
+ <div class='form-text-wrap'>
223
+ <label class="form-text">建物名</label>
224
+ <span class="form-any">任意</span>
225
+ </div>
226
+ <%= f.text_field :building_name, class:"input-default", id:"building", placeholder:"例)柳ビル103"%>
227
+ </div>
228
+ <div class="form-group">
229
+ <div class='form-text-wrap'>
230
+ <label class="form-text">電話番号</label>
231
+ <span class="indispensable">必須</span>
232
+ </div>
233
+ <%= f.text_field :phone, class:"input-default", id:"phone-number", placeholder:"例)09012345678",maxlength:"11"%>
234
+ </div>
235
+ </div>
236
+ <%# /配送先の入力 %>
237
+ <div class='buy-btn'>
238
+ <%= f.submit "購入" ,class:"buy-red-btn" %>
239
+ </div>
240
+ <% end %>
241
+ </div>
242
+ </div>
243
+ ```
244
+
245
+
112
246
  大変恐縮ですが、何が問題かご教授いただけませんでしょうか。
113
247
  超初心者のため謎コードが多いかもしれませんが、どうぞよろしくお願いいたします。

2

コードの誤字脱字修正

2020/10/30 05:20

投稿

pico0120
pico0120

スコア2

title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,7 @@
1
1
  Railsでフリマアプリのクローンアプリを作成中です。
2
2
  商品購入時に、商品の配送先(住所)情報と購入した商品の情報を同時にそれぞれのテーブルに保存できるようにしたいです。
3
3
 
4
- 自分では以下のように考えましたが、この記述では、"param is missing or the value is empty: order"というエラーが出てうまく情報を渡すことができません。
4
+ 自分では以下のように考えましたが、この記述では、"param is missing or the value is empty: order_address"というエラーが出てうまく情報を渡すことができません。
5
5
 
6
6
  Formオブジェクトで、まずフォームからパラメーターとして送られてきた情報をテーブルに保存する。
7
7
  order_address.rb
@@ -22,7 +22,7 @@
22
22
 
23
23
  def save
24
24
  Order.create(item:id)
25
- Address.create(pstal_code: postal_code, address_num: address_num, building_name: building_name, phone: phone)
25
+ Address.create(postal_code: postal_code, address_num: address_num, building_name: building_name, phone: phone)
26
26
  end
27
27
  end
28
28
 
@@ -53,7 +53,7 @@
53
53
 
54
54
  private
55
55
  def order_params
56
- params.require(:order).permit(:id).merge(token: params[:token])
56
+ params.require(:order_address).permit(:postal_code, :address_num, :building_name, :phone).merge(token: params[:token], user_id: current_user.id, item: id)
57
57
  end
58
58
 
59
59
  def pay_item

1

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

2020/10/29 09:21

投稿

pico0120
pico0120

スコア2

title CHANGED
File without changes
body CHANGED
@@ -3,8 +3,8 @@
3
3
 
4
4
  自分では以下のように考えましたが、この記述では、"param is missing or the value is empty: order"というエラーが出てうまく情報を渡すことができません。
5
5
 
6
- Formオブジェクトで、まず order_address.rbの中で、フォームからパラメーターとして送られてきた情報をテーブルに保存する。
6
+ Formオブジェクトで、まずフォームからパラメーターとして送られてきた情報をテーブルに保存する。
7
-
7
+ order_address.rb
8
8
  ```ruby
9
9
  class OrderAddress
10
10
  include ActiveModel::Model
@@ -29,7 +29,8 @@
29
29
 
30
30
 
31
31
  ```
32
- 次に、orders_controller.rbのnewアクション、createアクションでFormオブジェクトのインスタンスを生成するようにする。
32
+ 次に、コントローラーのnewアクション、createアクションでFormオブジェクトのインスタンスを生成するようにする。
33
+ orders_controller.rb
33
34
  ```ruby
34
35
  class OrdersController < ApplicationController
35
36
 
@@ -68,6 +69,7 @@
68
69
 
69
70
  ```
70
71
  (PAY.JPでクレジットカード決済機能もつけています。)
72
+ card.js
71
73
  ```ruby
72
74
 
73
75
  const pay = () => {