Skip to content

Confirmable with many emails

WANG QIANG edited this page Mar 4, 2016 · 2 revisions

Suppose you have a pattern like User has_many :emails (where one of the email acts as a :primary email)

You can use confirmable option in the following way. In your User model use

devise :confirmable, ...

has_many :emails
delegate :confirmation_sent_at, :confirmed_at, :confirmation_token, to: :primary_email

def primary_email
  emails.primary || (emails.first if new_record?)
end

This means your :confirmation_sent_at, :confirmed_at, :confirmation_token, :primary columns will reside in Email model

Any other ways?

There is a gem devise-multi_email which implements this properly and further lets you to recover password and send confirmations to any one of the user's emails.

Clone this wiki locally