instance method
each
Ruby on Rails 3.1.12
Since v2.2.3Signature
each()
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.
p.errors.add(:name, "can't be blank") p.errors.each do |attribute, errors_array| # Will yield :name and "can't be blank" end p.errors.add(:name, "must be specified") p.errors.each do |attribute, errors_array| # Will yield :name and "can't be blank" # then yield :name and "must be specified" end
Source
# File activemodel/lib/active_model/errors.rb, line 150
def each
messages.each_key do |attribute|
self[attribute].each { |error| yield attribute, error }
end
end
Defined in activemodel/lib/active_model/errors.rb line 150
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveModel::Errors