Update series_name
for alt styles to be null, with a fallback string
I considered this at first, but decided to keep it simple until it turned out to matter. Oops, it already matters, lol! I want the item search code to be able to easily tell if the series name is real or a placeholder, so we can decide whether to build the filter text in `fits:$series-$color-$species` form or `fits:alt-style-$id` form. So in this change, we keep it that `AltStyle#series_name` returns the placeholder string if none is set, but callers can explicitly ask whether it's a real series name or not. Will use this in our next change!
This commit is contained in:
parent
9243193bc8
commit
18c7a34b8f
3 changed files with 22 additions and 2 deletions
|
@ -17,6 +17,20 @@ class AltStyle < ApplicationRecord
|
||||||
species_human_name: species.human_name)
|
species_human_name: species.human_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# If the series_name hasn't yet been set manually by support staff, show the
|
||||||
|
# string "<New?>" instead. But it won't be searchable by that string—that is,
|
||||||
|
# `fits:<New?>-faerie-draik` intentionally will not work, and the canonical
|
||||||
|
# filter name will be `fits:alt-style-IDNUMBER`, instead.
|
||||||
|
def series_name
|
||||||
|
self[:series_name] || "<New?>"
|
||||||
|
end
|
||||||
|
|
||||||
|
# You can use this to check whether `series_name` is returning the actual
|
||||||
|
# value or its placeholder value.
|
||||||
|
def has_real_series_name?
|
||||||
|
self[:series_name].present?
|
||||||
|
end
|
||||||
|
|
||||||
def adjective_name
|
def adjective_name
|
||||||
"#{series_name} #{color.human_name}"
|
"#{series_name} #{color.human_name}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class ChangeDefaultForAltStylesSeriesName < ActiveRecord::Migration[7.1]
|
||||||
|
def change
|
||||||
|
change_column_null :alt_styles, :series_name, true
|
||||||
|
change_column_default :alt_styles, :series_name, from: "<New?>", to: nil
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,14 +10,14 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.1].define(version: 2024_02_27_231815) do
|
ActiveRecord::Schema[7.1].define(version: 2024_02_27_233743) do
|
||||||
create_table "alt_styles", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
|
create_table "alt_styles", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
|
||||||
t.integer "species_id", null: false
|
t.integer "species_id", null: false
|
||||||
t.integer "color_id", null: false
|
t.integer "color_id", null: false
|
||||||
t.integer "body_id", null: false
|
t.integer "body_id", null: false
|
||||||
t.datetime "created_at", precision: nil, null: false
|
t.datetime "created_at", precision: nil, null: false
|
||||||
t.datetime "updated_at", precision: nil, null: false
|
t.datetime "updated_at", precision: nil, null: false
|
||||||
t.string "series_name", default: "<New?>", null: false
|
t.string "series_name"
|
||||||
t.index ["color_id"], name: "index_alt_styles_on_color_id"
|
t.index ["color_id"], name: "index_alt_styles_on_color_id"
|
||||||
t.index ["species_id"], name: "index_alt_styles_on_species_id"
|
t.index ["species_id"], name: "index_alt_styles_on_species_id"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue