instance method each

Ruby on Rails 2.2.3

Since v2.2.3 Last seen in v2.3.18

Available 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 165
    def each
      @errors.each_key { |attr| @errors[attr].each { |msg| yield attr, msg } }
    end

Defined in activerecord/lib/active_record/validations.rb line 165 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::Errors

Type at least 2 characters to search.

↑↓ navigate · open · esc close