質問編集履歴

5

schema.rbの追加

2020/11/03 07:46

投稿

EleAco
EleAco

スコア15

test CHANGED
File without changes
test CHANGED
@@ -218,6 +218,180 @@
218
218
 
219
219
 
220
220
 
221
+ **schema.rb**
222
+
223
+
224
+
225
+ ```
226
+
227
+ # This file is auto-generated from the current state of the database. Instead
228
+
229
+ # of editing this file, please use the migrations feature of Active Record to
230
+
231
+ # incrementally modify your database, and then regenerate this schema definition.
232
+
233
+ #
234
+
235
+ # This file is the source Rails uses to define your schema when running `rails
236
+
237
+ # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
238
+
239
+ # be faster and is potentially less error prone than running all of your
240
+
241
+ # migrations from scratch. Old migrations may fail to apply correctly if those
242
+
243
+ # migrations use external dependencies or application code.
244
+
245
+ #
246
+
247
+ # It's strongly recommended that you check this file into your version control system.
248
+
249
+
250
+
251
+ ActiveRecord::Schema.define(version: 2020_10_23_085817) do
252
+
253
+
254
+
255
+ create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
256
+
257
+ t.string "name", null: false
258
+
259
+ t.string "record_type", null: false
260
+
261
+ t.bigint "record_id", null: false
262
+
263
+ t.bigint "blob_id", null: false
264
+
265
+ t.datetime "created_at", null: false
266
+
267
+ t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
268
+
269
+ t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
270
+
271
+ end
272
+
273
+
274
+
275
+ create_table "active_storage_blobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
276
+
277
+ t.string "key", null: false
278
+
279
+ t.string "filename", null: false
280
+
281
+ t.string "content_type"
282
+
283
+ t.text "metadata"
284
+
285
+ t.bigint "byte_size", null: false
286
+
287
+ t.string "checksum", null: false
288
+
289
+ t.datetime "created_at", null: false
290
+
291
+ t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
292
+
293
+ end
294
+
295
+
296
+
297
+ create_table "comments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
298
+
299
+ t.integer "user_id", null: false
300
+
301
+ t.integer "photo_id", null: false
302
+
303
+ t.text "text"
304
+
305
+ t.datetime "created_at", precision: 6, null: false
306
+
307
+ t.datetime "updated_at", precision: 6, null: false
308
+
309
+ end
310
+
311
+
312
+
313
+ create_table "favorites", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
314
+
315
+ t.integer "user_id", null: false
316
+
317
+ t.integer "photo_id", null: false
318
+
319
+ t.datetime "created_at", precision: 6, null: false
320
+
321
+ t.datetime "updated_at", precision: 6, null: false
322
+
323
+ end
324
+
325
+
326
+
327
+ create_table "photos", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
328
+
329
+ t.text "explanation", null: false
330
+
331
+ t.string "title", null: false
332
+
333
+ t.integer "user_id", null: false
334
+
335
+ t.datetime "created_at", precision: 6, null: false
336
+
337
+ t.datetime "updated_at", precision: 6, null: false
338
+
339
+ end
340
+
341
+
342
+
343
+ create_table "relationships", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
344
+
345
+ t.integer "following_id", null: false
346
+
347
+ t.integer "follower_id", null: false
348
+
349
+ t.datetime "created_at", precision: 6, null: false
350
+
351
+ t.datetime "updated_at", precision: 6, null: false
352
+
353
+ t.index ["follower_id", "following_id"], name: "index_relationships_on_follower_id_and_following_id", unique: true
354
+
355
+ end
356
+
357
+
358
+
359
+ create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
360
+
361
+ t.string "nickname", null: false
362
+
363
+ t.string "email", default: "", null: false
364
+
365
+ t.string "encrypted_password", default: "", null: false
366
+
367
+ t.text "profile"
368
+
369
+ t.string "reset_password_token"
370
+
371
+ t.datetime "reset_password_sent_at"
372
+
373
+ t.datetime "remember_created_at"
374
+
375
+ t.datetime "created_at", precision: 6, null: false
376
+
377
+ t.datetime "updated_at", precision: 6, null: false
378
+
379
+ t.index ["email"], name: "index_users_on_email", unique: true
380
+
381
+ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
382
+
383
+ end
384
+
385
+
386
+
387
+ add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
388
+
389
+ end
390
+
391
+ ```
392
+
393
+
394
+
221
395
 
222
396
 
223
397
  このようなコードになっております

4

コードを使いしました

2020/11/03 07:46

投稿

EleAco
EleAco

スコア15

test CHANGED
File without changes
test CHANGED
@@ -138,7 +138,7 @@
138
138
 
139
139
 
140
140
 
141
- ##追加コード
141
+ ##皆様のご指摘で追加したコード
142
142
 
143
143
  ```
144
144
 
@@ -168,6 +168,54 @@
168
168
 
169
169
 
170
170
 
171
+ **binding.pryにて@user.errors.messagesを追加**
172
+
173
+ ```
174
+
175
+ [1] pry(#<Users::RegistrationsController>)> @user.update
176
+
177
+ ArgumentError: wrong number of arguments (given 0, expected 1)
178
+
179
+ from /Users/eleaco/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.4/lib/active_record/persistence.rb:616:in `update'
180
+
181
+ [2] pry(#<Users::RegistrationsController>)> @user.errors.messages
182
+
183
+ => {:password=>["can't be blank", "is invalid"], :current_password=>["can't be blank"], :profile=>[]}#profileに記述しましたが空のようです
184
+
185
+ [3] pry(#<Users::RegistrationsController>)>
186
+
187
+ ```
188
+
189
+
190
+
191
+ **user.rb**
192
+
193
+ ```
194
+
195
+ devise :database_authenticatable, :registerable,
196
+
197
+ :recoverable, :rememberable, :validatable
198
+
199
+
200
+
201
+ with_options presence: true do |i|
202
+
203
+ i.validates :nickname
204
+
205
+ i.validates :email
206
+
207
+ i.validates :password
208
+
209
+ i.validates :encrypted_password
210
+
211
+ #profileを記述していない!!ここでしょうか…?
212
+
213
+ end
214
+
215
+ ```
216
+
217
+
218
+
171
219
 
172
220
 
173
221
 

3

追加でコードを記述しました!

2020/11/03 07:31

投稿

EleAco
EleAco

スコア15

test CHANGED
File without changes
test CHANGED
@@ -13,8 +13,6 @@
13
13
  **registrations_controller.rb**
14
14
 
15
15
  def update
16
-
17
- @user.update(account_update_params)
18
16
 
19
17
  super
20
18
 
@@ -90,7 +88,9 @@
90
88
 
91
89
  def update
92
90
 
93
- @user.update(account_update_params)
91
+ #@user.update(account_update_params)ここ消しました理由はbefore_actionで
92
+
93
+ #configure_account_update_parametersメソッドを呼び出しているからです
94
94
 
95
95
  end
96
96
 
@@ -138,6 +138,40 @@
138
138
 
139
139
 
140
140
 
141
+ ##追加コード
142
+
143
+ ```
144
+
145
+ **registrations_controller.rb**
146
+
147
+ def update
148
+
149
+ super
150
+
151
+ binding.pry
152
+
153
+ end
154
+
155
+ ```
156
+
157
+ **binding.pryで中に何が入っているか確認します**
158
+
159
+ ```
160
+
161
+ [2] pry(#<Users::RegistrationsController>)> @user
162
+
163
+ => #<User id: 2, nickname: "gest", email: "gest@gest", profile: "これは自己紹介です", created_at: "2020-11-01 00:55:52", updated_at: "2020-11-01 00:55:52">
164
+
165
+ ```
166
+
167
+ 自己紹介文は@userに入っています…しかし保存はできません…
168
+
169
+
170
+
171
+
172
+
173
+
174
+
141
175
  このようなコードになっております
142
176
 
143
177
  **皆様のお力をお貸しください!

2

エラー文の出力

2020/11/03 07:14

投稿

EleAco
EleAco

スコア15

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,29 @@
4
4
 
5
5
  ##エラー文
6
6
 
7
+ refistrations_controller.rbのupdateにbinding.pryでエラーを出力しております
7
8
 
9
+
10
+
11
+ ```
12
+
13
+ **registrations_controller.rb**
14
+
15
+ def update
16
+
17
+ @user.update(account_update_params)
18
+
19
+ super
20
+
21
+ binding.pry
22
+
23
+ end
24
+
25
+ ```
26
+
27
+
28
+
29
+ ターミナル上でエラー文を確認
8
30
 
9
31
  ```
10
32
 

1

エラー文の追加を行いました

2020/11/03 06:35

投稿

EleAco
EleAco

スコア15

test CHANGED
File without changes
test CHANGED
@@ -11,6 +11,8 @@
11
11
  [2] pry(#<Users::RegistrationsController>)> @user.update
12
12
 
13
13
  ArgumentError: wrong number of arguments (given 0, expected 1)
14
+
15
+ from /Users/eleaco/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.4/lib/active_record/persistence.rb:616:in `update'
14
16
 
15
17
  ```
16
18