【发布时间】:2015-10-30 13:14:04
【问题描述】:
我按照wiki 添加了一个带有设计的自定义电子邮件验证器。它可以工作,但每次验证都会打印两次错误,如下所示。如何解决这个问题?
更新: 评论中的答案linked 不起作用。它可能只有在一个验证调用中完成所有验证时才有效。在我的情况下,一个验证由设计完成,另一个由我添加。为了清楚起见,模型如下所示:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
attr_accessible :email, :name
before_save do |user|
user.email = email.downcase
end
validates :name, presence: true, length: { maximum: 50 }
validates :email, email: true, presence: true, reduce: true # This causes 'Email is Invalid' to be printed twice
end
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 validation devise email-validation