I am trying to add an email custom validators for my app; However, where should I place the custom validator? (I really do not want to place this validator class inside the model) Is there a cli generator for validator?
http://guides.rubyonrails.org/active_record_validations.html
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
record.errors[attribute] << (options[:message] || "is not an email")
end
end
end
class Person < ApplicationRecord
validates :email, presence: true, email: true
end
What's the convention location/path for custom validator?