From 89c729ecbeba569434d0ed3842ae307cb48df135 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Fri, 18 Oct 2024 17:04:26 -0700 Subject: [PATCH] Oops, fix bug preventing new alt styles from being saved Whoops, I didn't realize this change I made to validation for the alt style editing form, was goofing up alt style modeling! The trick is, the validation was happening before the `before_create` hook. Now I've reformulated these as `before_validation` hooks, so we're not rejecting new alt styles for having no thumbnail! --- app/models/alt_style.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/alt_style.rb b/app/models/alt_style.rb index e8a4f5d6..71ee47ce 100644 --- a/app/models/alt_style.rb +++ b/app/models/alt_style.rb @@ -12,8 +12,8 @@ class AltStyle < ApplicationRecord validates :series_name, presence: true, allow_nil: true validates :thumbnail_url, presence: true - before_create :infer_series_name - before_create :infer_thumbnail_url + before_validation :infer_series_name, unless: :has_real_series_name? + before_validation :infer_thumbnail_url, unless: :thumbnail_url? scope :matching_name, ->(series_name, color_name, species_name) { color = Color.find_by_name!(color_name) @@ -82,7 +82,7 @@ class AltStyle < ApplicationRecord # embarrassing. NOSTALGIC_FINAL_DAY = Date.new(2024, 12, 31) def infer_series_name - if !has_real_series_name? && Date.today <= NOSTALGIC_FINAL_DAY + if Date.today <= NOSTALGIC_FINAL_DAY self.series_name = "Nostalgic" end end