Class: CamaleonCms::UniqValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/models/camaleon_cms/term_taxonomy.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object


2
3
4
5
6
# File 'app/models/camaleon_cms/term_taxonomy.rb', line 2

def validate(record)
  unless record.skip_slug_validation?
    record.errors[:base] << "#{I18n.t('camaleon_cms.admin.post.message.requires_different_slug')}" if CamaleonCms::TermTaxonomy.where(slug: record.slug).where.not(id: record.id).where("#{CamaleonCms::TermTaxonomy.table_name}.taxonomy" => record.taxonomy).where("#{CamaleonCms::TermTaxonomy.table_name}.parent_id" => record.parent_id).size > 0
  end
end