質問編集履歴
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -339,3 +339,133 @@
|
|
339
339
|
ruby 2.5.7p206
|
340
340
|
|
341
341
|
Rails 5.2.4.1
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
### 追記
|
346
|
+
|
347
|
+
・users_controller内showアクションの記述を変更しました。
|
348
|
+
|
349
|
+
・users/show.html.erb内の記述を変更しました。
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
users_controller.rb
|
354
|
+
|
355
|
+
```
|
356
|
+
|
357
|
+
def show
|
358
|
+
|
359
|
+
@user = User.find(params[:id])
|
360
|
+
|
361
|
+
@post_images = @user.post_images.map(&:cosplay_image)
|
362
|
+
|
363
|
+
end
|
364
|
+
|
365
|
+
```
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
users/show.html.erb
|
370
|
+
|
371
|
+
```
|
372
|
+
|
373
|
+
<%= @post_images.each do |image| %>
|
374
|
+
|
375
|
+
<%= attachment_image_tag image, :cosplay_image %>
|
376
|
+
|
377
|
+
<% end %>
|
378
|
+
|
379
|
+
```
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
その際に下記のエラーが発生します。
|
384
|
+
|
385
|
+
![イメージ説明](2dc8da96d9d1c9995c5301c8b185d7ba.png)
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
恐らく、
|
390
|
+
|
391
|
+
・Userモデルにそもそもcosplay_imageというカラムが存在しない
|
392
|
+
|
393
|
+
・user.rbにattachment :cosplay_imageの記載が無い
|
394
|
+
|
395
|
+
のではないかと考えていますが、解決方法が分かりません。
|
396
|
+
|
397
|
+
アドバイスを頂けないでしょうか。
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
下記は、usersとpost_imagesのschemaです。
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
users
|
406
|
+
|
407
|
+
```
|
408
|
+
|
409
|
+
create_table "users", force: :cascade do |t|
|
410
|
+
|
411
|
+
t.string "email", default: "", null: false
|
412
|
+
|
413
|
+
t.string "encrypted_password", default: "", null: false
|
414
|
+
|
415
|
+
t.string "reset_password_token"
|
416
|
+
|
417
|
+
t.datetime "reset_password_sent_at"
|
418
|
+
|
419
|
+
t.datetime "remember_created_at"
|
420
|
+
|
421
|
+
t.string "name"
|
422
|
+
|
423
|
+
t.datetime "created_at", null: false
|
424
|
+
|
425
|
+
t.datetime "updated_at", null: false
|
426
|
+
|
427
|
+
t.string "profile_image_id"
|
428
|
+
|
429
|
+
t.string "like_cos"
|
430
|
+
|
431
|
+
t.text "introduction"
|
432
|
+
|
433
|
+
t.index ["email"], name: "index_users_on_email", unique: true
|
434
|
+
|
435
|
+
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
436
|
+
|
437
|
+
end
|
438
|
+
|
439
|
+
```
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
post_images
|
444
|
+
|
445
|
+
```
|
446
|
+
|
447
|
+
create_table "post_images", force: :cascade do |t|
|
448
|
+
|
449
|
+
t.text "real_image_name"
|
450
|
+
|
451
|
+
t.string "real_image_id"
|
452
|
+
|
453
|
+
t.text "caption"
|
454
|
+
|
455
|
+
t.integer "user_id"
|
456
|
+
|
457
|
+
t.datetime "created_at", null: false
|
458
|
+
|
459
|
+
t.datetime "updated_at", null: false
|
460
|
+
|
461
|
+
t.string "cosplay_image_id"
|
462
|
+
|
463
|
+
t.text "cosplay_image_name"
|
464
|
+
|
465
|
+
t.integer "favorites_count"
|
466
|
+
|
467
|
+
t.integer "cosplay_favorites_count"
|
468
|
+
|
469
|
+
end
|
470
|
+
|
471
|
+
```
|