Skip to content

Commit

Permalink
例外処理を他の箇所に移動させる
Browse files Browse the repository at this point in the history
  • Loading branch information
yocchan-git committed Mar 20, 2024
1 parent 06d2513 commit a97a765
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 1 addition & 3 deletions app/models/image_resizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ def initialize(attachment, resize_side: { width: 600, height: 600 })
def resize
@image_side = fetch_image_side
resize_size = fetch_resize_size_fit_and_crop
@attachment.variant(resize_to_fit: resize_size[:fit], crop: [*resize_size[:crop], @resize_side[:width], @resize_side[:height]]).processed.url
rescue Vips::Error
image_url default_image_path
@attachment.variant(resize_to_fit: resize_size[:fit], crop: [*resize_size[:crop], @resize_side[:width], @resize_side[:height]])
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,11 @@ def avatar_url

if avatar.attached?
image_resizer = ImageResizer.new(avatar, resize_side: { width: 120, height: 120 })
image_resizer.resize
image_resizer.resize.processed.url
else
image_url default_image_path
end
rescue ActiveStorage::FileNotFoundError, ActiveStorage::InvariableError
rescue ActiveStorage::FileNotFoundError, ActiveStorage::InvariableError, Vips::Error
image_url default_image_path
end

Expand Down

0 comments on commit a97a765

Please sign in to comment.