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:
evazion
2020-12-13 04:00:32 -06:00
parent 62b69eb133
commit 8d87b1a0c0
29 changed files with 108 additions and 109 deletions

View File

@@ -56,13 +56,13 @@ class FavoriteGroup < ApplicationRecord
if !creator.is_platinum?
error += " Upgrade your account to create more."
end
self.errors.add(:base, error)
errors.add(:base, error)
end
end
def validate_number_of_posts
if post_count > 10_000
errors[:base] << "Favorite groups can have up to 10,000 posts each"
errors.add(:base, "Favorite groups can have up to 10,000 posts each")
end
end
@@ -72,12 +72,12 @@ class FavoriteGroup < ApplicationRecord
nonexisting_post_ids = added_post_ids - existing_post_ids
if nonexisting_post_ids.present?
errors[:base] << "Cannot add invalid post(s) to favgroup: #{nonexisting_post_ids.to_sentence}"
errors.add(:base, "Cannot add invalid post(s) to favgroup: #{nonexisting_post_ids.to_sentence}")
end
duplicate_post_ids = post_ids.group_by(&:itself).transform_values(&:size).select { |id, count| count > 1 }.keys
if duplicate_post_ids.present?
errors[:base] << "Favgroup already contains post #{duplicate_post_ids.to_sentence}"
errors.add(:base, "Favgroup already contains post #{duplicate_post_ids.to_sentence}")
end
end