Fix ActiveModel::Errors#[]= deprecation warning
DEPRECATION WARNING: ActiveModel::Errors#[]= is deprecated and will be removed in Rails 5.1. Use model.errors.add(:attachment, "content type image/png does not match any of accepted content types pdf") instead. (called from validate_attachment_content_type at /home/travis/build/consul/consul/app/models/document.rb:92)
This commit is contained in:
@@ -80,24 +80,24 @@ class Document < ActiveRecord::Base
|
||||
def validate_attachment_size
|
||||
if documentable_class.present? &&
|
||||
attachment_file_size > documentable_class.max_file_size
|
||||
errors[:attachment] = I18n.t("documents.errors.messages.in_between",
|
||||
errors.add(:attachment, I18n.t("documents.errors.messages.in_between",
|
||||
min: "0 Bytes",
|
||||
max: "#{max_file_size(documentable_class)} MB")
|
||||
max: "#{max_file_size(documentable_class)} MB"))
|
||||
end
|
||||
end
|
||||
|
||||
def validate_attachment_content_type
|
||||
if documentable_class &&
|
||||
!accepted_content_types(documentable_class).include?(attachment_content_type)
|
||||
errors[:attachment] = I18n.t("documents.errors.messages.wrong_content_type",
|
||||
content_type: attachment_content_type,
|
||||
accepted_content_types: documentable_humanized_accepted_content_types(documentable_class))
|
||||
errors.add(:attachment, I18n.t("documents.errors.messages.wrong_content_type",
|
||||
content_type: attachment_content_type,
|
||||
accepted_content_types: documentable_humanized_accepted_content_types(documentable_class)))
|
||||
end
|
||||
end
|
||||
|
||||
def attachment_presence
|
||||
if attachment.blank? && cached_attachment.blank?
|
||||
errors[:attachment] = I18n.t("errors.messages.blank")
|
||||
errors.add(:attachment, I18n.t("errors.messages.blank"))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user