class User < ActiveRecord::Base
validates_each :name, :email do |model, attr, value|
if value =~ /groucho|harpo|chico/i
model.errors.add(attr, "You can't be serious, #{value}")
end
end
end
Confused as to how this works.
Is :name, email the items it will loop?
:nameand:emailare the attributes that will be validates using this block.So each time a User is validated, the block will be called once with
attr = :nameand once withattr = :email(and each timevaluewill hold the value of that attribute).