From bd6b6450d9e46cfdf8664de52ff02d7506cedeb6 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Wed, 5 Jun 2024 19:27:38 -0700 Subject: [PATCH] Handle newly-released species in Item Getting Guide MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is less likely than the newly-released color case for PB items, but I figure let's be resilient anyway, especially since it's so easy to—and also I figure this is less likely to be triggered by an *actual* new species, and more likely to be triggered by a surprise in an item's naming conventions. But yeah, if `Item#pb_species` returns `nil` upstream, it'll be passed to `Color#example_pet_type`, which will crash trying to read its ID. So in this change, we update `Color#example_pet_type` to accept a `nil` value, and fall back to the first Species (Acara) in that case. This means that, if you e.g. take the Mutant Aisha Collar and delete the word "Aisha" from the name, then load it in the Item Getting Guide, you'll see a thumbnail of a Mutant Acara. Good enough! --- app/models/color.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/color.rb b/app/models/color.rb index 42ee4415..e0c1aa70 100644 --- a/app/models/color.rb +++ b/app/models/color.rb @@ -21,7 +21,8 @@ class Color < ApplicationRecord end end - def example_pet_type(preferred_species: Species.first) + def example_pet_type(preferred_species: nil) + preferred_species ||= Species.first pet_types.order([Arel.sql("species_id = ? DESC"), preferred_species.id], "species_id ASC").first end