Say I have the following in a Rails 4 app:
class Person < ActiveRecord::Base
has_many :email_addresses, as: :emailable
has_one :user_account
end
class EmailAddress < ActiveRecord::Base
belongs_to :emailable, polymorphic: true
# There is an :address column
end
class UserAccount < ActiveRecord::Base
belongs_to :person
end
A person can have multiple email addresses. A person can also have a user account. (I've moved this into it's own model because not all people would be users.) Any of the person's email addresses could be used as the "username" when logging in.
Given this, I would like to use the Devise gem. I see you can specify the model to which the authentication is applied. User
is widely used, but I would be using UserAccount
. However, Devise then expects the email (username) field to be in this model.
When a person registers a user account, there would actually be three associated records created (Person
, EmailAddress
, and UserAccount
). I can't figure out how to to get Devise to work with this setup. Any ideas?