我正在尝试为我的应用添加电子邮件自定义验证器; 但是,我应该在哪里放置自定义验证器?(我真的不想将这个验证器类放在模型中)是否有用于验证器的cli生成器?
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
Run Code Online (Sandbox Code Playgroud)
自定义验证器的约定位置/路径是什么?