質問編集履歴
2
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -196,10 +196,6 @@
|
|
196
196
|
|
197
197
|
|
198
198
|
|
199
|
-
```ruby
|
200
|
-
|
201
|
-
|
202
|
-
|
203
199
|
|
204
200
|
|
205
201
|
|
@@ -338,7 +334,7 @@
|
|
338
334
|
|
339
335
|
こちらが@user.update!にした時のエラー文です
|
340
336
|
|
341
|
-
https://gyazo.com/2cc0f56667a78a3e3f9f4bcc9bd292a9
|
337
|
+
https://i.gyazo.com/2cc0f56667a78a3e3f9f4bcc9bd292a9.png
|
342
338
|
|
343
339
|
|
344
340
|
|
1
【1】 app/models/user.rb のコード 【2】 db/schema.rb の users 部分 【3】 binding.pry で止めた状態で、「 @user.errors.ful
test
CHANGED
File without changes
|
test
CHANGED
@@ -86,6 +86,124 @@
|
|
86
86
|
|
87
87
|
|
88
88
|
|
89
|
+
```ruby
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
class User < ApplicationRecord
|
94
|
+
|
95
|
+
has_one_attached :image
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
devise :database_authenticatable, :registerable,
|
100
|
+
|
101
|
+
:recoverable, :rememberable, :validatable
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
validates :nickname, :birthday, presence: true
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
validates :password, format: { with: /\A(?=.*?[a-z])(?=.*?[\d])[a-z\d]+\z/i}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
with_options presence: true, format: { with: /\A[ぁ-んァ-ヶ一-龥々]+\z/ } do
|
114
|
+
|
115
|
+
validates :first_name
|
116
|
+
|
117
|
+
validates :last_name
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
with_options presence: true, format: {with:/\A[ァ-ヶ]+\z/} do
|
124
|
+
|
125
|
+
validates :first_name_katakana
|
126
|
+
|
127
|
+
validates :last_name_katakana
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
has_many :celebs, through: :rooms
|
134
|
+
|
135
|
+
has_many :rooms, dependent: :destroy
|
136
|
+
|
137
|
+
has_many :messages, dependent: :destroy
|
138
|
+
|
139
|
+
has_one :card, dependent: :destroy
|
140
|
+
|
141
|
+
has_many :likes, dependent: :destroy
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
```
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
|
155
|
+
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
156
|
+
|
157
|
+
t.string "email", default: "", null: false
|
158
|
+
|
159
|
+
t.string "encrypted_password", default: "", null: false
|
160
|
+
|
161
|
+
t.string "nickname", null: false
|
162
|
+
|
163
|
+
t.string "last_name", null: false
|
164
|
+
|
165
|
+
t.string "first_name", null: false
|
166
|
+
|
167
|
+
t.string "first_name_katakana", null: false
|
168
|
+
|
169
|
+
t.string "last_name_katakana", null: false
|
170
|
+
|
171
|
+
t.date "birthday", null: false
|
172
|
+
|
173
|
+
t.boolean "order", default: false
|
174
|
+
|
175
|
+
t.string "reset_password_token"
|
176
|
+
|
177
|
+
t.datetime "reset_password_sent_at"
|
178
|
+
|
179
|
+
t.datetime "remember_created_at"
|
180
|
+
|
181
|
+
t.datetime "created_at", precision: 6, null: false
|
182
|
+
|
183
|
+
t.datetime "updated_at", precision: 6, null: false
|
184
|
+
|
185
|
+
t.boolean "admin", default: false
|
186
|
+
|
187
|
+
t.index ["email"], name: "index_users_on_email", unique: true
|
188
|
+
|
189
|
+
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
```
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
89
207
|
### 試したこと
|
90
208
|
|
91
209
|
|
@@ -166,6 +284,64 @@
|
|
166
284
|
|
167
285
|
しかし2回目でupdateアクションを行うとfalseと返って来るのですが4回目ではorderがtrueとなっています。
|
168
286
|
|
287
|
+
|
288
|
+
|
289
|
+
3: def create
|
290
|
+
|
291
|
+
4: redirect_to new_card_path and return unless current_user.card.present?
|
292
|
+
|
293
|
+
5:
|
294
|
+
|
295
|
+
6: @price = Price.find(params[:price_id])
|
296
|
+
|
297
|
+
7:
|
298
|
+
|
299
|
+
8: Payjp.api_key = ENV["PAYJP_SECRET_KEY"]
|
300
|
+
|
301
|
+
9: customer_token = current_user.card.customer_token
|
302
|
+
|
303
|
+
10: Payjp::Charge.create(
|
304
|
+
|
305
|
+
11: amount: @price.content,
|
306
|
+
|
307
|
+
12: customer: customer_token,
|
308
|
+
|
309
|
+
13: currency: 'jpy'
|
310
|
+
|
311
|
+
14: )
|
312
|
+
|
313
|
+
15:
|
314
|
+
|
315
|
+
16: @room = Room.find(params[:room_id])
|
316
|
+
|
317
|
+
17: @order = Order.create(price_id: @price.id, room_id: @room.id)
|
318
|
+
|
319
|
+
18: @message = Message.create(room_id: @room.id, user_id: @room.user.id, content:"#{current_user.nickname}さんから#{@price.content}円が送られました!!", order: true)
|
320
|
+
|
321
|
+
19: @user = User.find(current_user.id)
|
322
|
+
|
323
|
+
20: @user.update(order: true)
|
324
|
+
|
325
|
+
=> 21: binding.pry
|
326
|
+
|
327
|
+
22: ActionCable.server.broadcast 'stanp_channel', content: @message
|
328
|
+
|
329
|
+
[1] pry(#<OrdersController>)> @user.errors.full_messages
|
330
|
+
|
331
|
+
=> ["パスワードは不正な値です"]
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
こちらがbinding.pryをして@user.errors.full_messagesを記述した際のものです
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
こちらが@user.update!にした時のエラー文です
|
340
|
+
|
341
|
+
https://gyazo.com/2cc0f56667a78a3e3f9f4bcc9bd292a9https://gyazo.com/2cc0f56667a78a3e3f9f4bcc9bd292a9
|
342
|
+
|
343
|
+
|
344
|
+
|
169
345
|
自分にはこの解決方法がわかりません。
|
170
346
|
|
171
347
|
お力添えをしていただけるとありがたいです。
|