Class: UniqueNestedValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- UniqueNestedValidator
- Defined in:
- lib/unique_nested_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
2 3 4 5 6 7 8 9 |
# File 'lib/unique_nested_validator.rb', line 2 def validate_each(record, attribute, value) if not attribute.empty? with = [:with] || :id if value.collect{|c| c[with]}.uniq.length != value.length record.errors.add(attribute, [:message] || "#{I18n.t('unique_nested_validator.errors.cannot_repeat', default: 'cannot repeat')} #{I18n.t(with.to_s.pluralize, scope: [:unique_nested_validator, :keys], default: with.to_s.pluralize)}") end end end |