Displaying 1 result from an estimated 1 matches for "validates_with".
2012 Aug 05
0
ActiveRecord::Validator vs ActiveModel::Validator
...ils 3 code in a Rails 3 book and get confused:
Class EmailValidator < ActiveRecord::Validator
def validate()
email_field = options[:attr]
record.errors[email_field] << “is not valid” unless
record.send(email_field) =~ /^[a-z]$/
end
end
class Account < ActiveRecord::Base
validates_with EmailValidator, :attr => :email
end
Where is this ActiveRecord::Validator coming from? Also why does it
exist when you can simply do this in ActiveModel:
class RandomlyValidator < ActiveModel::Validator
def validate(record)
record.errors[:base] << “FAIL #1” unless first_hurdle(r...