Class: Amalgam::Validator::Slug

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/amalgam/validators/slug.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



3
4
5
6
7
8
# File 'lib/amalgam/validators/slug.rb', line 3

def validate(record)
  slug_field = options[:field] || :slug
  unless record.send(slug_field) =~ /\A[0-9a-z\-_]+\z/
    record.errors.add(attribute, :invalid, options)
  end
end