Class: Categoryz3::Validators::ChildItemCategoryValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/categoryz3/validators/child_item_category_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



4
5
6
7
8
# File 'lib/categoryz3/validators/child_item_category_validator.rb', line 4

def validate(record)
  unless record.master_item.category.path.map{ |category| category.id }.include?(record.category_id)
    record.errors[:category] << "Must match with master_item.category"
  end
end