instance method
each_error
Ruby on Rails 2.3.18
Since v2.3.18 Last seen in v2.3.18Signature
each_error()
Yields each attribute and associated error 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_error{|attr,err| puts "#{attr} - #{err.type}" }
# => name - :too_short
# name - :blank
# address - :blank
Source
# File activerecord/lib/active_record/validations.rb, line 254
def each_error
@errors.each_key { |attr| @errors[attr].each { |error| yield attr, error } }
end
Defined in activerecord/lib/active_record/validations.rb line 254
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Errors