Skip to content

Commit d93bfac

Browse files
committed
Adds explanation of :base attribute to errors.add
[ci skip]
1 parent bdab7b1 commit d93bfac

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

activemodel/lib/active_model/errors.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,13 @@ def to_hash(full_messages = false)
289289
# # => NameIsInvalid: name is invalid
290290
#
291291
# person.errors.messages # => {}
292+
#
293+
# +attribute+ should be set to <tt>:base</tt> if the error is not
294+
# directly associated with a single attribute.
295+
#
296+
# person.errors.add(:base, "either name or email must be present")
297+
# person.errors.messages
298+
# # => {:base=>["either name or email must be present"]}
292299
def add(attribute, message = :invalid, options = {})
293300
message = normalize_message(attribute, message, options)
294301
if exception = options[:strict]

0 commit comments

Comments
 (0)