Module: StaticList::Validate::ClassMethods

Defined in:
lib/static_list.rb

Instance Method Summary collapse

Instance Method Details

#validates_static_list_value(attribute, model, options = {}) ⇒ Object

Method to validate in the receiving model that the value received is included in the static list model. For example : with_options(:allow_blank => true) do |options|

options.validate_static_list_value :hair_color,          HairColor
options.validate_static_list_value :ethnicity,           Ethnicity
options.validate_static_list_value :sex,                 Sex

end



30
31
32
33
# File 'lib/static_list.rb', line 30

def validates_static_list_value(attribute, model, options = {})
  options.merge!(:in => model.static_list_codes.map { |el| el[1] })
  validates_inclusion_of attribute, options
end