Skip to content

Commit

Permalink
メソッドをDecoratorからModelに移動
Browse files Browse the repository at this point in the history
  • Loading branch information
naokinaokiboo committed Sep 18, 2024
1 parent 8ec5464 commit 95d7b58
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
17 changes: 0 additions & 17 deletions app/decorators/practice_decorator.rb

This file was deleted.

14 changes: 14 additions & 0 deletions app/models/practice.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class Practice < ApplicationRecord
OGP_IMAGE_SIZE = [1200, 630].freeze

include Watchable
include Searchable

Expand Down Expand Up @@ -168,6 +170,18 @@ def include_must_read_books?
practices_books.any?(&:must_read)
end

def ogp_image_url
default_image_path = '/ogp/ogp.png'

if ogp_image.attached?
ogp_image.variant(resize_to_fill: OGP_IMAGE_SIZE, autorot: true, saver: { strip: true, quality: 60 }).processed.url
else
image_url default_image_path
end
rescue ActiveStorage::FileNotFoundError, ActiveStorage::InvariableError, Vips::Error
image_url default_image_path
end

private

def total_learning_minute(report)
Expand Down

0 comments on commit 95d7b58

Please sign in to comment.