From bf47dff77a75ad0b8fa7e87ecd981d67bfa4ba12 Mon Sep 17 00:00:00 2001 From: Alexander Zubkov Date: Wed, 23 Feb 2011 20:58:33 +0300 Subject: [PATCH] Add i18n support, some code cleanup --- lib/validate_email.rb | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/lib/validate_email.rb b/lib/validate_email.rb index 1c75c65..6348533 100644 --- a/lib/validate_email.rb +++ b/lib/validate_email.rb @@ -1,26 +1,17 @@ -require 'active_model' require 'mail' module ActiveModel module Validations class EmailValidator < ActiveModel::EachValidator - - def initialize(options) - options.reverse_merge!(:message => "is not a valid email address") - super(options) - end - def validate_each(record, attribute, value) - return if options[:allow_nil] && value.nil? - begin mail = Mail::Address.new(value) unless mail.address == value && mail.domain.split(".").length > 1 - record.errors.add(attribute, options[:message]) + record.errors.add(attribute, :invalid_email, :default => options[:message], :value => value) end rescue - record.errors.add(attribute, options[:message]) + record.errors.add(attribute, :invalid_email, :default => options[:message], :value => value) end end end