質問編集履歴
6
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
|
12
12
|
class Work < ApplicationRecord
|
13
13
|
|
14
|
+
has_rich_text :content
|
14
15
|
has_many_attached :content
|
15
16
|
|
16
17
|
validate :include_blob
|
5
title
CHANGED
File without changes
|
body
CHANGED
@@ -15,15 +15,15 @@
|
|
15
15
|
|
16
16
|
validate :include_blob
|
17
17
|
|
18
|
-
def include_blob
|
18
|
+
def include_blob
|
19
|
-
|
19
|
+
if content.attached?
|
20
|
-
|
20
|
+
if !['.jpg', '.png', '.gif'].include?(content.blob.content_type)
|
21
|
-
|
21
|
+
errors.add(:content, I18n.t('errors.messages.file_type_not_image'))
|
22
|
-
|
22
|
+
elsif file.size > 10.megabyte
|
23
|
-
|
23
|
+
errors.add(:content, I18n.t('errors.messages.file_size_over'))
|
24
|
-
|
24
|
+
end
|
25
|
-
|
25
|
+
end
|
26
|
-
end
|
26
|
+
end
|
27
27
|
|
28
28
|
end
|
29
29
|
|
4
インデント
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,15 +14,16 @@
|
|
14
14
|
has_many_attached :content
|
15
15
|
|
16
16
|
validate :include_blob
|
17
|
+
|
17
|
-
|
18
|
+
def include_blob
|
18
|
-
|
19
|
+
if content.attached?
|
19
|
-
|
20
|
+
if !['.jpg', '.png', '.gif'].include?(content.blob.content_type)
|
20
|
-
|
21
|
+
errors.add(:content, I18n.t('errors.messages.file_type_not_image'))
|
21
|
-
|
22
|
+
elsif file.size > 10.megabyte
|
22
|
-
|
23
|
+
errors.add(:content, I18n.t('errors.messages.file_size_over'))
|
23
|
-
end
|
24
|
-
end
|
25
24
|
end
|
25
|
+
end
|
26
|
+
end
|
26
27
|
|
27
28
|
end
|
28
29
|
|
3
s
title
CHANGED
File without changes
|
body
CHANGED
@@ -15,11 +15,11 @@
|
|
15
15
|
|
16
16
|
validate :include_blob
|
17
17
|
def include_blob
|
18
|
-
if content.
|
18
|
+
if content.attached?
|
19
19
|
if !['.jpg', '.png', '.gif'].include?(content.blob.content_type)
|
20
20
|
errors.add(:content, I18n.t('errors.messages.file_type_not_image'))
|
21
21
|
elsif file.size > 10.megabyte
|
22
|
-
errors.add(:content, I18n.t('errors.messages.
|
22
|
+
errors.add(:content, I18n.t('errors.messages.file_size_over'))
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
2
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,12 +14,12 @@
|
|
14
14
|
has_many_attached :content
|
15
15
|
|
16
16
|
validate :include_blob
|
17
|
-
|
17
|
+
def include_blob
|
18
|
-
|
18
|
+
if content.value.attached?
|
19
|
-
|
19
|
+
if !['.jpg', '.png', '.gif'].include?(content.blob.content_type)
|
20
|
-
|
20
|
+
errors.add(:content, I18n.t('errors.messages.file_type_not_image'))
|
21
|
-
|
21
|
+
elsif file.size > 10.megabyte
|
22
|
-
|
22
|
+
errors.add(:content, I18n.t('errors.messages.file_type_not_image'))
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
1
コードタグの挿入
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
undefined method `value' for #<ActionText::RichText:0x00007f629a7652d8> Did you mean? validate
|
8
8
|
|
9
9
|
### 該当のソースコード
|
10
|
+
```Ruby
|
10
11
|
|
11
12
|
class Work < ApplicationRecord
|
12
13
|
|
@@ -24,6 +25,9 @@
|
|
24
25
|
end
|
25
26
|
|
26
27
|
end
|
28
|
+
|
29
|
+
```
|
30
|
+
|
27
31
|
### 試したこと
|
28
32
|
|
29
33
|
active_storage_validationなどのgemでactivestorageにバリデーションをした
|