我正在为我当前的项目使用 Riak 数据库,它不支持“唯一性”辅助方法。现在我想验证用户电子邮件的唯一性。如何编写唯一电子邮件地址的自定义验证??
最佳答案
尝试这样的事情。如果这不适用于您的数据库,您可能需要修改 User.exists?
部分。
class User
validate :verify_unique_email
def verify_unique_email
if User.exists? email: email
errors.add :email, 'has already been taken'
end
end
end
关于ruby-on-rails - 电子邮件唯一性的 Rails 3 自定义验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23102622/