Class: SingletonValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/validators/singleton_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



3
4
5
6
7
# File 'app/validators/singleton_validator.rb', line 3

def validate(record)
  if record.class.count > 0
    record.errors.add(:id, "there can be only one #{record.class}")
  end
end