Class: MustBeAValueValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/app/validators/must_be_a_value_validator.rb

Overview

usage:

in your model, add:

validates :sex, :must_be_a_value => true;

this checks against the objects attribute_values

Instance Method Summary collapse

Instance Method Details

#error_messageObject



9
10
11
# File 'lib/app/validators/must_be_a_value_validator.rb', line 9

def error_message
  "is geen geldige keuze."
end

#help_messageObject



13
14
# File 'lib/app/validators/must_be_a_value_validator.rb', line 13

def help_message
end

#validate_each(record, attribute, value) ⇒ Object



16
17
18
19
20
21
# File 'lib/app/validators/must_be_a_value_validator.rb', line 16

def validate_each(record, attribute, value)
  values = attribute_values(record, attribute)
  if values.assoc(value).nil?
    record.errors[attribute] << (options[:message] || error_message )
  end
end