models: fix deprecated errors[:base] << "message" calls.
Replace the idiom `errors[:base] << "message"` with `errors.add(:base, "message")`. The former is deprecated in Rails 6.1.
This commit is contained in:
@@ -490,7 +490,7 @@ class Post < ApplicationRecord
|
||||
|
||||
invalid_tags.each do |tag|
|
||||
tag.errors.messages.each do |attribute, messages|
|
||||
warnings[:base] << "Couldn't add tag: #{messages.join(';')}"
|
||||
warnings.add(:base, "Couldn't add tag: #{messages.join(';')}")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -976,7 +976,7 @@ class Post < ApplicationRecord
|
||||
module DeletionMethods
|
||||
def expunge!
|
||||
if is_status_locked?
|
||||
self.errors.add(:is_status_locked, "; cannot delete post")
|
||||
errors.add(:is_status_locked, "; cannot delete post")
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -1082,11 +1082,11 @@ class Post < ApplicationRecord
|
||||
def copy_notes_to(other_post, copy_tags: NOTE_COPY_TAGS)
|
||||
transaction do
|
||||
if id == other_post.id
|
||||
errors.add :base, "Source and destination posts are the same"
|
||||
errors.add(:base, "Source and destination posts are the same")
|
||||
return false
|
||||
end
|
||||
unless has_notes?
|
||||
errors.add :post, "has no notes"
|
||||
errors.add(:post, "has no notes")
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -1357,8 +1357,7 @@ class Post < ApplicationRecord
|
||||
module ValidationMethods
|
||||
def post_is_not_its_own_parent
|
||||
if !new_record? && id == parent_id
|
||||
errors[:base] << "Post cannot have itself as a parent"
|
||||
false
|
||||
errors.add(:base, "Post cannot have itself as a parent")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1372,7 +1371,7 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
def uploader_is_not_limited
|
||||
errors[:uploader] << uploader.upload_limit.limit_reason if uploader.upload_limit.limited?
|
||||
errors.add(:uploader, uploader.upload_limit.limit_reason) if uploader.upload_limit.limited?
|
||||
end
|
||||
|
||||
def added_tags_are_valid
|
||||
@@ -1382,12 +1381,12 @@ class Post < ApplicationRecord
|
||||
if new_general_tags.present?
|
||||
n = new_general_tags.size
|
||||
tag_wiki_links = new_general_tags.map { |tag| "[[#{tag.name}]]" }
|
||||
self.warnings[:base] << "Created #{n} new #{(n == 1) ? "tag" : "tags"}: #{tag_wiki_links.join(", ")}"
|
||||
warnings.add(:base, "Created #{n} new #{(n == 1) ? "tag" : "tags"}: #{tag_wiki_links.join(", ")}")
|
||||
end
|
||||
|
||||
new_artist_tags.each do |tag|
|
||||
if tag.artist.blank?
|
||||
self.warnings[:base] << "Artist [[#{tag.name}]] requires an artist entry. \"Create new artist entry\":[/artists/new?artist%5Bname%5D=#{CGI.escape(tag.name)}]"
|
||||
warnings.add(:base, "Artist [[#{tag.name}]] requires an artist entry. \"Create new artist entry\":[/artists/new?artist%5Bname%5D=#{CGI.escape(tag.name)}]")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1398,7 +1397,7 @@ class Post < ApplicationRecord
|
||||
|
||||
if unremoved_tags.present?
|
||||
unremoved_tags_list = unremoved_tags.map { |t| "[[#{t}]]" }.to_sentence
|
||||
self.warnings[:base] << "#{unremoved_tags_list} could not be removed. Check for implications and try again"
|
||||
warnings.add(:base, "#{unremoved_tags_list} could not be removed. Check for implications and try again")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1409,21 +1408,21 @@ class Post < ApplicationRecord
|
||||
return if tags.any?(&:artist?)
|
||||
return if Sources::Strategies.find(source).is_a?(Sources::Strategies::Null)
|
||||
|
||||
self.warnings[:base] << "Artist tag is required. \"Create new artist tag\":[/artists/new?artist%5Bsource%5D=#{CGI.escape(source)}]. Ask on the forum if you need naming help"
|
||||
warnings.add(:base, "Artist tag is required. \"Create new artist tag\":[/artists/new?artist%5Bsource%5D=#{CGI.escape(source)}]. Ask on the forum if you need naming help")
|
||||
end
|
||||
|
||||
def has_copyright_tag
|
||||
return if !new_record?
|
||||
return if has_tag?("copyright_request") || tags.any?(&:copyright?)
|
||||
|
||||
self.warnings[:base] << "Copyright tag is required. Consider adding [[copyright request]] or [[original]]"
|
||||
warnings.add(:base, "Copyright tag is required. Consider adding [[copyright request]] or [[original]]")
|
||||
end
|
||||
|
||||
def has_enough_tags
|
||||
return if !new_record?
|
||||
|
||||
if tags.count(&:general?) < 10
|
||||
self.warnings[:base] << "Uploads must have at least 10 general tags. Read [[howto:tag]] for guidelines on tagging your uploads"
|
||||
warnings.add(:base, "Uploads must have at least 10 general tags. Read [[howto:tag]] for guidelines on tagging your uploads")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user