質問編集履歴

1

コードの最新化

2021/01/04 01:12

投稿

jm_swim
jm_swim

スコア8

test CHANGED
File without changes
test CHANGED
@@ -84,15 +84,29 @@
84
84
 
85
85
  belongs_to :coach, optional: true
86
86
 
87
- has_one_attached :image, optional: true
87
+ has_one_attached :image
88
-
88
+
89
- has_one_attached :video, optional: true
89
+ has_one_attached :video
90
+
91
+
92
+
90
-
93
+ comment = Comment.last
94
+
91
-
95
+ comment.video.attach(
96
+
92
-
97
+ io: File.open("path/to/video"),
98
+
99
+ filename: "video.txt",
100
+
101
+ content_type: "text/plain"
102
+
103
+ )
104
+
105
+
106
+
93
- validates :content, presence: true, unless: :was_attached? || :is_attached?
107
+ validates :content, presence: true, unless: :was_attached?
94
-
108
+
95
- validates :image, presence: true, unless: :is_attached?
109
+ validates :content, presence: true, unless: :is_attached?
96
110
 
97
111
 
98
112
 
@@ -112,10 +126,10 @@
112
126
 
113
127
 
114
128
 
115
- mount_uploader :video, VideoUploader
116
-
117
129
  end
118
130
 
131
+
132
+
119
133
  ```
120
134
 
121
135
 
@@ -176,8 +190,6 @@
176
190
 
177
191
  end
178
192
 
179
- binding.pry
180
-
181
193
  end
182
194
 
183
195
 
@@ -188,30 +200,24 @@
188
200
 
189
201
  def coach_comment_params
190
202
 
191
- if coach_signed_in?
192
-
193
203
  params.require(:comment).permit(:content, :image, :video).merge(coach_id: current_coach.id)
194
204
 
195
- end
196
-
197
205
  end
198
206
 
199
207
 
200
208
 
201
209
  def user_comment_params
202
210
 
203
- if user_signed_in?
204
-
205
211
  params.require(:comment).permit(:content, :image, :video).merge(user_id: current_user.id)
206
212
 
207
- end
208
-
209
213
  end
210
214
 
211
215
  end
212
216
 
213
217
 
214
218
 
219
+
220
+
215
221
  ```
216
222
 
217
223