質問編集履歴

1

追記

2022/08/28 22:54

投稿

ssk
ssk

スコア332

test CHANGED
File without changes
test CHANGED
@@ -36,3 +36,35 @@
36
36
  end
37
37
  end
38
38
  ```
39
+ ### 追記
40
+ ```ruby
41
+
42
+ class DocumentFileUploader < CarrierWave::Uploader::Base
43
+ include CarrierWave::MiniMagick
44
+
45
+ process :fix_exif_rotation, if: :image?
46
+ process :strip, if: :image?
47
+
48
+ version :thumb, if: :image? do
49
+ process resize_and_pad: [300, 300]
50
+ end
51
+
52
+ def store_dir
53
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
54
+ end
55
+
56
+ def size_range
57
+ 1..2.megabytes
58
+ end
59
+
60
+ def extension_allowlist
61
+ %w(jpg jpeg gif png pdf docx xlsx xlsm pptx doc xls ppt txt zip csv msg)
62
+ end
63
+
64
+ private
65
+
66
+ def image?(file)
67
+ file.content_type.include? 'image'
68
+ end
69
+ end
70
+ ```追記