From f55bfe726045594c78438841cdccd5843522deab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 20 Feb 2015 20:57:56 -0200 Subject: Change the deprecation messages to show the preferred way to work with ActiveModel::Errors --- activemodel/lib/active_model/errors.rb | 12 ++++++------ activemodel/lib/active_model/validator.rb | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 166911f0fa..8334747615 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -114,9 +114,9 @@ module ActiveModel # person.errors.get(:age) # => [] def get(key) ActiveSupport::Deprecation.warn(<<-MESSAGE.squish) - ActiveModel::Errors#get is deprecated and will be removed in Rails 5.1 + ActiveModel::Errors#get is deprecated and will be removed in Rails 5.1. - To achieve the same use messages[:#{key}] + To achieve the same use model.errors[:#{key}]. MESSAGE messages[key] @@ -129,9 +129,9 @@ module ActiveModel # person.errors.get(:name) # => ["can't be nil"] def set(key, value) ActiveSupport::Deprecation.warn(<<-MESSAGE.squish) - ActiveModel::Errors#set is deprecated and will be removed in Rails 5.1 + ActiveModel::Errors#set is deprecated and will be removed in Rails 5.1. - To achieve the same use messages[:#{key}] = "#{value}" + Use model.errors.add(:#{key}, #{value.inspect}) instead. MESSAGE messages[key] = value @@ -162,9 +162,9 @@ module ActiveModel # person.errors[:name] # => ['must be set'] def []=(attribute, error) ActiveSupport::Deprecation.warn(<<-MESSAGE.squish) - ActiveModel::Errors#[]= is deprecated and will be removed in Rails 5.1 + ActiveModel::Errors#[]= is deprecated and will be removed in Rails 5.1. - To achieve the same use messages[:#{attribute}] << "#{error}" + Use model.errors.add(:#{attribute}, #{error.inspect}) instead. MESSAGE messages[attribute.to_sym] << error diff --git a/activemodel/lib/active_model/validator.rb b/activemodel/lib/active_model/validator.rb index 5752771d8c..1d2888a818 100644 --- a/activemodel/lib/active_model/validator.rb +++ b/activemodel/lib/active_model/validator.rb @@ -15,7 +15,7 @@ module ActiveModel # class MyValidator < ActiveModel::Validator # def validate(record) # if some_complex_logic - # record.errors.messages[:base] << "This record is invalid" + # record.errors.add(:base, "This record is invalid") # end # end # -- cgit v1.2.3