aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/deprecated_error_methods.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activemodel/lib/active_model/deprecated_error_methods.rb')
-rw-r--r--activemodel/lib/active_model/deprecated_error_methods.rb21
1 files changed, 8 insertions, 13 deletions
diff --git a/activemodel/lib/active_model/deprecated_error_methods.rb b/activemodel/lib/active_model/deprecated_error_methods.rb
index e0cbd9ba29..433de8931a 100644
--- a/activemodel/lib/active_model/deprecated_error_methods.rb
+++ b/activemodel/lib/active_model/deprecated_error_methods.rb
@@ -1,18 +1,18 @@
module ActiveModel
module DeprecatedErrorMethods
def on(attribute)
- ActiveSupport::Deprecation.warn "Errors#on have been deprecated, use Errors#[] instead"
- self[attribute]
+ message = "Errors#on have been deprecated, use Errors#[] instead.\n"
+ message << "Also note that the behaviour of Errors#[] has changed. Errors#[] now always returns an Array. An empty Array is "
+ message << "returned when there are no errors on the specified attribute."
+ ActiveSupport::Deprecation.warn(message)
+
+ errors = self[attribute]
+ errors.size < 2 ? errors.first : errors
end
def on_base
ActiveSupport::Deprecation.warn "Errors#on_base have been deprecated, use Errors#[:base] instead"
- on(:base)
- end
-
- def add(attribute, msg = Errors.default_error_messages[:invalid])
- ActiveSupport::Deprecation.warn "Errors#add(attribute, msg) has been deprecated, use Errors#[attribute] << msg instead"
- self[attribute] << msg
+ ActiveSupport::Deprecation.silence { on(:base) }
end
def add_to_base(msg)
@@ -25,11 +25,6 @@ module ActiveModel
self[attribute].any?
end
- def full_messages
- ActiveSupport::Deprecation.warn "Errors#full_messages has been deprecated, use Errors#to_a instead"
- to_a
- end
-
def each_full
ActiveSupport::Deprecation.warn "Errors#each_full has been deprecated, use Errors#to_a.each instead"
to_a.each { |error| yield error }