Class: Sandra::KeyValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Sandra::KeyValidator
- Defined in:
- lib/sandra/key_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/sandra/key_validator.rb', line 3 def validate_each(record, attribute, value) if record.attributes[attribute.to_s].nil? record.errors[attribute] << "#{attribute.to_s} cannot be nil." else record.errors[attribute] << "#{record.attributes[attribute.to_s]} has been taken." if record.new_record? && record.class.get(record.attributes[attribute.to_s]) end end |