Rails Gem Devise是否有解决方案允许用户拥有多个电子邮件? [英] Is there a solution for Rails Gem Devise to allow a user to have multiple emails?
问题描述
我正在寻找一个解决方案,让我的应用上的用户拥有超过1封电子邮件。这应该类似于Facebook,LinkedIn和Quora。帐户可以有多个电子邮件,1个作为主要邮件。
I'm looking for a solution to allow a user on my app to have more than 1 email. This should work similar to Facebook, LinkedIn and Quora. Where an account can have multiple emails, 1 as the primary.
有没有一个交钥匙解决方案的设计avaialble?我希望不要从头开始写这个,因为它很常见。
Is there a turn-key solution for devise avaialble? I'm hoping to not have to write this from scratch given it's so common.
想法?谢谢
推荐答案
嗯...我建议创建新的模型,你会做这样的事情:
Hm...I'll suggest to create new model, You'll do something like this:
例如,模型将是 UserEmail
。
class UserEmail < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_many :user_emails
end
并覆盖devise的方法在中找到记录用户
模型:
and override devise's method to find record in User
model:
def self.find_first_by_auth_conditions(warden_conditions)
conditions = warden_conditions.dup
if email = conditions.delete(:email)
User.includes(:user_emails).where('user_emails.email = ?', email).first
else
super(warden_conditions)
end
Read more about override here: https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address
这篇关于Rails Gem Devise是否有解决方案允许用户拥有多个电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!