Method: ActiveModel::Errors#each
- Defined in:
- lib/reactive_record/active_record/errors.rb
#each ⇒ Object
Iterates through each error key, value pair in the error messages hash. Yields the attribute and the error for that attribute. If the attribute has more than one error message, yields once for each error message.
person.errors.add(:name, :blank, message: "can't be blank")
person.errors.each do |attribute, error|
# Will yield :name and "can't be blank"
end
person.errors.add(:name, :not_specified, message: "must be specified")
person.errors.each do |attribute, error|
# Will yield :name and "can't be blank"
# then yield :name and "must be specified"
end
49 50 51 52 53 |
# File 'lib/reactive_record/active_record/errors.rb', line 49 def each .each_key do |attribute| [attribute].each { |error| yield attribute, error } end end |