From 52d76a4f2250979ad246c65cd26c66ccc294df85 Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 7 Mar 2021 20:26:52 -0600 Subject: [PATCH] artists: fix error messages for invalid artist names. * When trying to create an artist entry for a non-artist tag, set the error on the name attribute so that the artist name gets marked as incorrect in the artist edit form. * Fix a bad `Name '' cannot be blank` error message when the artist name is blank. * Fix showing wiki pages of non-artist tags in the artist edit form when the artist name conflicts with a non-artist tag (e.g. if you try to create an artist named '1girl', don't show the wiki for 1girl in the artist edit form). --- app/logical/tag_name_validator.rb | 2 +- app/models/artist.rb | 3 ++- app/views/artists/_form.html.erb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/logical/tag_name_validator.rb b/app/logical/tag_name_validator.rb index 1a48c53c9..c71d32852 100644 --- a/app/logical/tag_name_validator.rb +++ b/app/logical/tag_name_validator.rb @@ -10,7 +10,7 @@ class TagNameValidator < ActiveModel::EachValidator case value when /\A_*\z/ - record.errors.add(attribute, "'#{value}' cannot be blank") + record.errors.add(attribute, "cannot be blank") when /\*/ record.errors.add(attribute, "'#{value}' cannot contain asterisks ('*')") when /,/ diff --git a/app/models/artist.rb b/app/models/artist.rb index a9e1e3c4e..ef1e67e11 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -12,6 +12,7 @@ class Artist < ApplicationRecord validate :validate_tag_category validates :name, tag_name: true, uniqueness: true + before_save :update_tag_category after_save :create_version after_save :clear_url_string_changed @@ -155,7 +156,7 @@ class Artist < ApplicationRecord return unless !is_deleted? && name_changed? && tag.present? if tag.category_name != "Artist" && !tag.empty? - errors.add(:base, "'#{name}' is a #{tag.category_name.downcase} tag; artist entries can only be created for artist tags") + errors.add(:name, "'#{name}' is a #{tag.category_name.downcase} tag; artist entries can only be created for artist tags") end end diff --git a/app/views/artists/_form.html.erb b/app/views/artists/_form.html.erb index 8a72d56fb..8a1309627 100644 --- a/app/views/artists/_form.html.erb +++ b/app/views/artists/_form.html.erb @@ -5,7 +5,7 @@ <%= f.input :group_name %> <%= f.input :url_string, label: "URLs", as: :text, input_html: { value: params.dig(:artist, :url_string) || @artist.urls.join("\n")}, hint: "You can prefix a URL with - to mark it as dead." %> - <% if @artist.wiki_page.present? %> + <% if @artist.tag&.artist? && @artist.wiki_page.present? %>