class SlugValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless value =~ /^[a-z0-9-]+$/ record.errors[attribute] << (options[:message] || I18n.t('errors.messages.slug')) end end end