class SlugValidator < ActiveModel::Validator def validate(record) if Dimensions::Slug.where(value: record.value, slugable_type: record.slugable_type).any? record.errors.add(:slug, "is already in use, chose another one.") end end end module Dimensions class Slug < Dimension validates_with SlugValidator end end