each() public

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, "can't be blank")
person.errors.each do |attribute, error|
  # Will yield :name and "can't be blank"
end

person.errors.add(:name, "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
Show source
Register or log in to add new notes.