質問編集履歴
1
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -56,6 +56,76 @@
|
|
56
56
|
|
57
57
|
```
|
58
58
|
|
59
|
+
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
class Comment < ApplicationRecord
|
64
|
+
|
65
|
+
belongs_to :post
|
66
|
+
|
67
|
+
belongs_to :user
|
68
|
+
|
69
|
+
validates :body, presence: true
|
70
|
+
|
71
|
+
has_many :likes
|
72
|
+
|
73
|
+
has_many :liked_users, through: :likes, source: :user
|
74
|
+
|
75
|
+
validates_uniqueness_of :Evaluation, scope: :user_id
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
class Post < ApplicationRecord
|
88
|
+
|
89
|
+
belongs_to :user
|
90
|
+
|
91
|
+
has_many :comments
|
92
|
+
|
93
|
+
has_many :likes
|
94
|
+
|
95
|
+
has_many :liked_users, through: :likes, source: :user
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
validates :user, presence: true
|
100
|
+
|
101
|
+
validates :content, presence: true
|
102
|
+
|
103
|
+
#validates :image, presence: true
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
serialize :image, Array
|
108
|
+
|
109
|
+
mount_uploaders :image, ImageUploader
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
scope :get_by_title, ->(title) {
|
114
|
+
|
115
|
+
where("title like ?", "%#{title}%")
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
scope :get_by_genre, ->(genre) {
|
120
|
+
|
121
|
+
where("genre like ?", "%#{genre}%")
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
```
|
128
|
+
|
59
129
|
参考サイト:https://qiita.com/nojinoji/items/2c66499848d882c31ffa
|
60
130
|
|
61
131
|
|