Handle newly-released PB items in Item Getting Guide

Oh right, it's possible for `Item#pb?` to return true, but
`Item#pb_color` to return `nil`, if the item has the paintbrush item
description but we can't find a color whose name matches the item name.
This would be expected if a new color were added to Neopets, and PB
items for it were modeled by the community, but we hadn't manually
added the color to the database yet.

Previously, the Item Getting Guide would crash in this scenario. Now,
it correctly handles the possibility of a `nil` value for `pb_color`,
and shows some placeholder info.

To test this, I temporarily edited some item names to not contain the
color name anymore (e.g. "P-rate Elephante Shirt and Vest"), then
loaded the guide and made changes until it no longer crashed.
This commit is contained in:
Emi Matchu 2024-06-05 19:20:57 -07:00
parent e1c598e591
commit 3dab235335
2 changed files with 14 additions and 8 deletions

View file

@ -134,10 +134,10 @@ class ItemsController < ApplicationController
# Also, PB items have some special handling: we group them by color, then # Also, PB items have some special handling: we group them by color, then
# load example pet types for the colors that don't have paint brushes. # load example pet types for the colors that don't have paint brushes.
@pb_items_by_color = @pb_items.group_by(&:pb_color). @pb_items_by_color = @pb_items.group_by(&:pb_color).
sort_by { |color, items| color.name }.to_h sort_by { |color, items| color&.name }.to_h
colors_without_thumbnails = colors_without_thumbnails = @pb_items_by_color.keys.
@pb_items_by_color.keys.reject(&:pb_item_thumbnail_url?) select(&:present?).reject(&:pb_item_thumbnail_url?)
@pb_color_pet_types = colors_without_thumbnails.map do |color| @pb_color_pet_types = colors_without_thumbnails.map do |color|
# Infer the ideal species from the first item we can, then try to find a # Infer the ideal species from the first item we can, then try to find a

View file

@ -64,27 +64,33 @@
%table.item-list{"data-group-type": "bundle"} %table.item-list{"data-group-type": "bundle"}
%thead %thead
%td.thumbnail-cell %td.thumbnail-cell
- if color.pb_item_thumbnail_url? - if color&.pb_item_thumbnail_url?
= image_tag color.pb_item_thumbnail_url, = image_tag color.pb_item_thumbnail_url,
alt: "Item thumbnail for #{color.pb_item_name}" alt: "Item thumbnail for #{color.pb_item_name}"
- else - elsif color
= image_tag pet_type_image_url(@pb_color_pet_types[color], size: :face), = image_tag pet_type_image_url(@pb_color_pet_types[color], size: :face),
srcset: ["#{pet_type_image_url(@pb_color_pet_types[color], size: :face_2x)} 2x"], srcset: ["#{pet_type_image_url(@pb_color_pet_types[color], size: :face_2x)} 2x"],
alt: @pb_color_pet_types[color].human_name alt: @pb_color_pet_types[color].human_name
%th %th
#{color.pb_item_name || color.name.humanize} - if color
#{color.pb_item_name || color.name.humanize}
- else
??? New color
(#{pluralize items.size, "item"}) (#{pluralize items.size, "item"})
%td.actions-cell %td.actions-cell
- if color.pb_item_name? - if color&.pb_item_name?
= button_link_to "Shops", = button_link_to "Shops",
shop_wizard_url_for(color.pb_item_name), shop_wizard_url_for(color.pb_item_name),
target: "_blank", icon: search_icon target: "_blank", icon: search_icon
= button_link_to "Trades", = button_link_to "Trades",
trading_post_url_for(color.pb_item_name), trading_post_url_for(color.pb_item_name),
target: "_blank", icon: search_icon target: "_blank", icon: search_icon
- else - elsif color
.special-color-explanation .special-color-explanation
Get via Lab Ray, morphing potions, etc. Get via Lab Ray, morphing potions, etc.
- else
.special-color-explanation
We don't have info about this color yet.
%tbody %tbody
- items.each do |item| - items.each do |item|
= render "item_list_row", item: = render "item_list_row", item: