Skip to content

How to: Confirmable with many email addresses per user

Max Calabrese edited this page Sep 20, 2017 · 1 revision

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. *

  • Note this gem only supports a Devise Model named 'user' at this point
Clone this wiki locally