teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

6

2019/06/20 02:33

投稿

liptr
liptr

スコア12

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

2019/06/20 02:33

投稿

liptr
liptr

スコア12

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
- if content.attached?
19
+ if content.attached?
20
- if !['.jpg', '.png', '.gif'].include?(content.blob.content_type)
20
+ if !['.jpg', '.png', '.gif'].include?(content.blob.content_type)
21
- errors.add(:content, I18n.t('errors.messages.file_type_not_image'))
21
+ errors.add(:content, I18n.t('errors.messages.file_type_not_image'))
22
- elsif file.size > 10.megabyte
22
+ elsif file.size > 10.megabyte
23
- errors.add(:content, I18n.t('errors.messages.file_size_over'))
23
+ errors.add(:content, I18n.t('errors.messages.file_size_over'))
24
- end
24
+ end
25
- end
25
+ end
26
- end
26
+ end
27
27
 
28
28
  end
29
29
 

4

インデント

2019/06/19 06:08

投稿

liptr
liptr

スコア12

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
- def include_blob
18
+ def include_blob
18
- if content.attached?
19
+ if content.attached?
19
- if !['.jpg', '.png', '.gif'].include?(content.blob.content_type)
20
+ if !['.jpg', '.png', '.gif'].include?(content.blob.content_type)
20
- errors.add(:content, I18n.t('errors.messages.file_type_not_image'))
21
+ errors.add(:content, I18n.t('errors.messages.file_type_not_image'))
21
- elsif file.size > 10.megabyte
22
+ elsif file.size > 10.megabyte
22
- errors.add(:content, I18n.t('errors.messages.file_size_over'))
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

2019/06/19 06:07

投稿

liptr
liptr

スコア12

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.value.attached?
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.file_type_not_image'))
22
+ errors.add(:content, I18n.t('errors.messages.file_size_over'))
23
23
  end
24
24
  end
25
25
  end

2

2019/06/18 06:42

投稿

liptr
liptr

スコア12

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
-   def include_blob
17
+ def include_blob
18
- if content.value.attached?
18
+ if content.value.attached?
19
- if !['.jpg', '.png', '.gif'].include?(content.blob.content_type)
19
+ if !['.jpg', '.png', '.gif'].include?(content.blob.content_type)
20
- errors.add(:content, I18n.t('errors.messages.file_type_not_image'))
20
+ errors.add(:content, I18n.t('errors.messages.file_type_not_image'))
21
- elsif file.size > 10.megabyte
21
+ elsif file.size > 10.megabyte
22
- errors.add(:content, I18n.t('errors.messages.file_type_not_image'))
22
+ errors.add(:content, I18n.t('errors.messages.file_type_not_image'))
23
23
  end
24
24
  end
25
25
  end

1

コードタグの挿入

2019/06/18 04:23

投稿

liptr
liptr

スコア12

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にバリデーションをした