ralinc/rails-blog

View on GitHub
app/validators/slug_validator.rb

Summary

Maintainability
A
0 mins
Test Coverage
class SlugValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    return if value =~ /\A[a-z-]+\z/
    record.errors[attribute] << (options[:message] || 'is not a valid slug')
  end
end