From b2b418284d1abcfb590767923dfac4028275d2db Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sun, 8 Apr 2018 14:45:29 +0200 Subject: [PATCH] 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) --- app/models/direct_upload.rb | 2 +- app/models/document.rb | 12 ++++++------ app/models/image.rb | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/models/direct_upload.rb b/app/models/direct_upload.rb index c4d1456e7..088c8ea64 100644 --- a/app/models/direct_upload.rb +++ b/app/models/direct_upload.rb @@ -51,7 +51,7 @@ class DirectUpload @relation.valid? if @relation.errors.key? :attachment - errors[:attachment] = @relation.errors[:attachment] + errors.add(:attachment, @relation.errors.full_messages_for(:attachment)) end end diff --git a/app/models/document.rb b/app/models/document.rb index 108f29fad..e8524bc72 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -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 diff --git a/app/models/image.rb b/app/models/image.rb index 8f62f94d8..a782d1916 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -79,23 +79,23 @@ class Image < ActiveRecord::Base def validate_attachment_size if imageable_class && attachment_file_size > 1.megabytes - errors[:attachment] = I18n.t("images.errors.messages.in_between", - min: "0 Bytes", - max: "#{imageable_max_file_size} MB") + errors.add(:attachment, I18n.t("images.errors.messages.in_between", + min: "0 Bytes", + max: "#{imageable_max_file_size} MB")) end end def validate_attachment_content_type if imageable_class && !attachment_of_valid_content_type? - errors[:attachment] = I18n.t("images.errors.messages.wrong_content_type", - content_type: attachment_content_type, - accepted_content_types: imageable_humanized_accepted_content_types) + errors.add(:attachment, I18n.t("images.errors.messages.wrong_content_type", + content_type: attachment_content_type, + accepted_content_types: imageable_humanized_accepted_content_types)) 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