Class: ParentValidator

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

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object


2
3
4
5
6
# File 'app/validators/parent_validator.rb', line 2

def validate(record)
  unless record.parent_id.nil? or Category.exists?(id: record.parent_id)
    record.errors[:parent_id] << (options[:message] || "Parent doesn't exist.")
  end
end