Skip to content

Commit

Permalink
only validate image when changed
Browse files Browse the repository at this point in the history
  • Loading branch information
kookster committed Dec 21, 2024
1 parent fb4a998 commit c4d03cd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/models/episode_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ class EpisodeImage < ApplicationRecord

belongs_to :episode, touch: true, optional: true

validates :height, :width, numericality: {greater_than_or_equal_to: 1400, less_than_or_equal_to: 3000}, if: :status_complete?
validates :width, comparison: {equal_to: :height}, if: :status_complete?
validates :height, :width, numericality: {greater_than_or_equal_to: 1400, less_than_or_equal_to: 3000}, if: :should_validate?
validates :width, comparison: {equal_to: :height}, if: :should_validate?

def should_validate?
status_complete? && (height_changed? || width_changed?)
end

def destination_path
"#{episode.path}/#{image_path}"
Expand Down

0 comments on commit c4d03cd

Please sign in to comment.