質問編集履歴
5
posts_controllerのif @post.saveを変更。
test
CHANGED
File without changes
|
test
CHANGED
@@ -613,3 +613,9 @@
|
|
613
613
|
|
614
614
|
|
615
615
|
![イメージ説明](5526c78a9c0d20df2a4b02cf3dbae3d9.png)
|
616
|
+
|
617
|
+
|
618
|
+
|
619
|
+
posts_controllerのif @post.saveを変更。
|
620
|
+
|
621
|
+
![イメージ説明](5e5fa3cb988ae92d3363231e2d398cf7.png)
|
4
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -591,3 +591,25 @@
|
|
591
591
|
end
|
592
592
|
|
593
593
|
```
|
594
|
+
|
595
|
+
|
596
|
+
|
597
|
+
|
598
|
+
|
599
|
+
> 追記
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
index.html.erbの中の
|
604
|
+
|
605
|
+
<img src="<%= "/post_images/#{post.post.post_image}" %>">を
|
606
|
+
|
607
|
+
<img src="<%= "/post_images/#{post.post_image}" %>">
|
608
|
+
|
609
|
+
に変更し、エラーは消えましたが画像がうまく表示できませんでした。
|
610
|
+
|
611
|
+
![イメージ説明](953930373e09fca80d345de9ce119a8c.png)
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
![イメージ説明](5526c78a9c0d20df2a4b02cf3dbae3d9.png)
|
3
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -505,3 +505,89 @@
|
|
505
505
|
|
506
506
|
|
507
507
|
```
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
### schema.rb
|
512
|
+
|
513
|
+
```rails
|
514
|
+
|
515
|
+
# This file is auto-generated from the current state of the database. Instead
|
516
|
+
|
517
|
+
# of editing this file, please use the migrations feature of Active Record to
|
518
|
+
|
519
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
520
|
+
|
521
|
+
#
|
522
|
+
|
523
|
+
# Note that this schema.rb definition is the authoritative source for your
|
524
|
+
|
525
|
+
# database schema. If you need to create the application database on another
|
526
|
+
|
527
|
+
# system, you should be using db:schema:load, not running all the migrations
|
528
|
+
|
529
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
530
|
+
|
531
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
532
|
+
|
533
|
+
#
|
534
|
+
|
535
|
+
# It's strongly recommended that you check this file into your version control system.
|
536
|
+
|
537
|
+
|
538
|
+
|
539
|
+
ActiveRecord::Schema.define(version: 2020_10_30_055415) do
|
540
|
+
|
541
|
+
|
542
|
+
|
543
|
+
create_table "likes", force: :cascade do |t|
|
544
|
+
|
545
|
+
t.integer "user_id"
|
546
|
+
|
547
|
+
t.integer "post_id"
|
548
|
+
|
549
|
+
t.datetime "created_at", null: false
|
550
|
+
|
551
|
+
t.datetime "updated_at", null: false
|
552
|
+
|
553
|
+
end
|
554
|
+
|
555
|
+
|
556
|
+
|
557
|
+
create_table "posts", force: :cascade do |t|
|
558
|
+
|
559
|
+
t.text "content"
|
560
|
+
|
561
|
+
t.datetime "created_at", null: false
|
562
|
+
|
563
|
+
t.datetime "updated_at", null: false
|
564
|
+
|
565
|
+
t.integer "user_id"
|
566
|
+
|
567
|
+
t.string "post_image"
|
568
|
+
|
569
|
+
end
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
create_table "users", force: :cascade do |t|
|
574
|
+
|
575
|
+
t.string "name"
|
576
|
+
|
577
|
+
t.string "email"
|
578
|
+
|
579
|
+
t.datetime "created_at", null: false
|
580
|
+
|
581
|
+
t.datetime "updated_at", null: false
|
582
|
+
|
583
|
+
t.string "image_name"
|
584
|
+
|
585
|
+
t.string "password"
|
586
|
+
|
587
|
+
end
|
588
|
+
|
589
|
+
|
590
|
+
|
591
|
+
end
|
592
|
+
|
593
|
+
```
|
2
ファイル名の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,12 +6,14 @@
|
|
6
6
|
|
7
7
|
どこがおかしいのでしょうか?
|
8
8
|
|
9
|
-
|
9
|
+
>
|
10
10
|
|
11
11
|
![イメージ説明](9e69bb2268e0fb69bb67b32a5ba8c90a.png)
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
+
### index.html.erb
|
16
|
+
|
15
17
|
```rails
|
16
18
|
|
17
19
|
<div class="main posts-index">
|
@@ -76,6 +78,10 @@
|
|
76
78
|
|
77
79
|
|
78
80
|
|
81
|
+
### posts_controller.rb
|
82
|
+
|
83
|
+
|
84
|
+
|
79
85
|
```rails
|
80
86
|
|
81
87
|
class PostsController < ApplicationController
|
@@ -222,7 +228,7 @@
|
|
222
228
|
|
223
229
|
|
224
230
|
|
225
|
-
|
231
|
+
### users_controller.rb
|
226
232
|
|
227
233
|
```rails
|
228
234
|
|
@@ -412,7 +418,7 @@
|
|
412
418
|
|
413
419
|
```
|
414
420
|
|
415
|
-
|
421
|
+
### application_record.rb
|
416
422
|
|
417
423
|
```rails
|
418
424
|
|
@@ -426,7 +432,7 @@
|
|
426
432
|
|
427
433
|
```
|
428
434
|
|
429
|
-
|
435
|
+
### like.rb
|
430
436
|
|
431
437
|
```rails
|
432
438
|
|
@@ -442,7 +448,7 @@
|
|
442
448
|
|
443
449
|
```
|
444
450
|
|
445
|
-
|
451
|
+
### post.rb
|
446
452
|
|
447
453
|
```rails
|
448
454
|
|
@@ -470,6 +476,8 @@
|
|
470
476
|
|
471
477
|
```
|
472
478
|
|
479
|
+
### user.rb
|
480
|
+
|
473
481
|
```rails
|
474
482
|
|
475
483
|
class User < ApplicationRecord
|
1
modelの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -411,3 +411,89 @@
|
|
411
411
|
end
|
412
412
|
|
413
413
|
```
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
```rails
|
418
|
+
|
419
|
+
class ApplicationRecord < ActiveRecord::Base
|
420
|
+
|
421
|
+
self.abstract_class = true
|
422
|
+
|
423
|
+
end
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
```
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
```rails
|
432
|
+
|
433
|
+
class Like < ApplicationRecord
|
434
|
+
|
435
|
+
validates :user_id, {presence: true}
|
436
|
+
|
437
|
+
validates :post_id, {presence: true}
|
438
|
+
|
439
|
+
end
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
```
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
```rails
|
448
|
+
|
449
|
+
class Post < ApplicationRecord
|
450
|
+
|
451
|
+
validates :content, {presence: true, length: {maximum: 140}}
|
452
|
+
|
453
|
+
validates :user_id, {presence: true}
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
# インスタンスメソッドuserを定義してください
|
458
|
+
|
459
|
+
def user
|
460
|
+
|
461
|
+
return User.find_by(id: self.user_id)
|
462
|
+
|
463
|
+
end
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
end
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
```
|
472
|
+
|
473
|
+
```rails
|
474
|
+
|
475
|
+
class User < ApplicationRecord
|
476
|
+
|
477
|
+
validates :name, {presence: true}
|
478
|
+
|
479
|
+
validates :email, {presence: true, uniqueness: true}
|
480
|
+
|
481
|
+
validates :password, {presence: true}
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
# インスタンスメソッドpostsを定義してください
|
486
|
+
|
487
|
+
def posts
|
488
|
+
|
489
|
+
return Post.where(user_id: self.id)
|
490
|
+
|
491
|
+
end
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
end
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
```
|