#14 共通のサムネとタイトルの取得は完成

このコミットが含まれているのは:
2025-06-04 01:17:43 +09:00
コミット 7719a9ea9d
8個のファイルの変更1221行の追加26行の削除
+14
ファイルの表示
@@ -1,3 +1,6 @@
require 'mini_magick'
class Post < ApplicationRecord
belongs_to :parent, class_name: 'Post', optional: true, foreign_key: 'parent_id'
belongs_to :uploaded_user, class_name: 'User', optional: true
@@ -12,4 +15,15 @@ class Post < ApplicationRecord
thumbnail, only_path: false) :
nil })
end
def resized_thumbnail!
return unless thumbnail.attached?
image = MiniMagick::Image.read(thumbnail.download)
image.resize '180x180'
thumbnail.purge
thumbnail.attach(io: File.open(image.path),
filename: 'resized_thumbnail.jpg',
content_type: 'image/jpeg')
end
end