public Method

Errors.each() { |attr, msg| ... }

Yields each attribute and associated message per error added.

Examples

my_person = Person.new(params[:person])

my_person.errors.add('login', 'can not be empty') if my_person.login == ''
my_person.errors.add('password', 'can not be empty') if my_person.password == ''
messages = ''
my_person.errors.each {|attr, msg| messages += attr.humanize + " " + msg + "<br />"}
messages
# => "Login can not be empty<br />Password can not be empty<br />"

Source Code

# File active_resource/validations.rb, line 128
def each
  @errors.each_key { |attr| @errors[attr].each { |msg| yield attr, msg } }
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.