lib/devise/multi_email/models/validatable.rb in devise-multi_email-1.0.0 vs lib/devise/multi_email/models/validatable.rb in devise-multi_email-1.0.1
- old
+ new
@@ -23,10 +23,11 @@
module MultiEmailValidatable
extend ActiveSupport::Concern
included do
devise :validatable
+ validates Devise::Models::MultiEmailAuthenticatable::EMAILS_ASSOCIATION, presence: true
after_validation :propagate_email_errors
email_class.send :include, EmailValidatable
end
@@ -39,10 +40,15 @@
def email_changed?
false
end
def propagate_email_errors
- return if (email_errors = errors.delete(self.class::EMAILS_ASSOCIATION)).nil?
+ email_error_key = self.class::EMAILS_ASSOCIATION
+ if respond_to?("#{self.class::EMAILS_ASSOCIATION}_attributes=")
+ email_error_key = "#{email_error_key}.email".to_sym
+ end
+
+ return if (email_errors = errors.delete(email_error_key)).nil?
email_errors.each do |error|
errors.add(:email, error)
end
end
\ No newline at end of file