質問編集履歴
1
ソースコードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -36,3 +36,45 @@
|
|
36
36
|
どうすればコメントした人のDeviseで登録したIDやユーザー名を表示させることができるのでしょうか
|
37
37
|
必要なファイルを言っていただければ提示いたします
|
38
38
|
|
39
|
+
|
40
|
+
|
41
|
+
追記
|
42
|
+
Userモデル
|
43
|
+
```Ruby
|
44
|
+
class User < ApplicationRecord
|
45
|
+
# Include default devise modules. Others available are:
|
46
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
47
|
+
devise :database_authenticatable, :registerable,
|
48
|
+
:recoverable, :rememberable, :validatable
|
49
|
+
|
50
|
+
mount_uploader :avatar, AvatarUploader
|
51
|
+
has_many :tweets, dependent: :destroy
|
52
|
+
has_many :comments, dependent: :destroy
|
53
|
+
end
|
54
|
+
|
55
|
+
```
|
56
|
+
Tweetモデル
|
57
|
+
```Ruby
|
58
|
+
class Tweet < ApplicationRecord
|
59
|
+
mount_uploader :image, ImageUploader
|
60
|
+
belongs_to :user
|
61
|
+
has_many :comments, dependent: :destroy
|
62
|
+
|
63
|
+
|
64
|
+
validates :title, presence: true
|
65
|
+
|
66
|
+
validates :body, presence: true
|
67
|
+
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
```
|
72
|
+
Commentモデル
|
73
|
+
```Ruby
|
74
|
+
class Comment < ApplicationRecord
|
75
|
+
mount_uploader :image, ImageUploader
|
76
|
+
belongs_to :tweet
|
77
|
+
belongs_to :user
|
78
|
+
end
|
79
|
+
|
80
|
+
```
|