2010-01-07 12:44:35 -05:00
|
|
|
class PersonWithValidator
|
|
|
|
include ActiveModel::Validations
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2010-01-07 12:44:35 -05:00
|
|
|
class PresenceValidator < ActiveModel::EachValidator
|
|
|
|
def validate_each(record, attribute, value)
|
|
|
|
record.errors[attribute] << "Local validator#{options[:custom]}" if value.blank?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-20 21:35:41 -04:00
|
|
|
class LikeValidator < ActiveModel::EachValidator
|
|
|
|
def initialize(options)
|
|
|
|
@with = options[:with]
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_each(record, attribute, value)
|
|
|
|
unless value[@with]
|
|
|
|
record.errors.add attribute, "does not appear to be like #{@with}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-07 12:44:35 -05:00
|
|
|
attr_accessor :title, :karma
|
|
|
|
end
|