class Users::ApplyAuthenticationForm include ActiveModel::Model attr_accessor :name, :id_number, :upload_image validates :name, presence: true validate :validate_ID_number def validate_ID_number logger.info("##id_number: #{id_number}") if id_number.present? && (id_number =~ User::VALID_NUMBER_REGEX).present? raise("身份证格式不对") end end end