instance method
each
Ruby on Rails 2.3.18
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
each()
Yields each attribute and associated message per error added.
class Company < ActiveRecord::Base validates_presence_of :name, :address, :email validates_length_of :name, :in => 5..30 end company = Company.create(:address => '123 First St.') company.errors.each{|attr,msg| puts "#{attr} - #{msg}" } # => name - is too short (minimum is 5 characters) # name - can't be blank # address - can't be blank
Source
# File activerecord/lib/active_record/validations.rb, line 238
def each
@errors.each_key { |attr| @errors[attr].each { |error| yield attr, error.message } }
end
Defined in activerecord/lib/active_record/validations.rb line 238
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Errors