#14 共通のサムネとタイトルの取得は完成
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user