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

This commit is contained in:
2025-06-04 01:17:43 +09:00
parent 0afba7f345
commit 7719a9ea9d
8 changed files with 1221 additions and 26 deletions
+14
View File
@@ -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