Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
698 views
in Technique[技术] by (71.8m points)

ruby on rails - Devise - how to change setting so that email addresses don't need to be unique

I set up Devise to log in with a username instead of email address because a significant number of our users share the same email address with their spouse. It is a unique market that we serve. But each spouse needs separate accounts to record personality instrument results.

The database no longer requires a unique email address so it will accept the same email addy for two accounts. However, Devise is still requiring a unique email address for each account. Is there a setting or a work around that i can use to change this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

= User Model

def email_required?
  false
end

def email_changed?
  false
end

# For ActiveRecord 5.1+
def will_save_change_to_email?
  false
end

= Migration

rails g migration update_index_on_users
def up
  sql = 'DROP INDEX index_users_on_email'
  sql << ' ON users' if Rails.env == 'production' # Heroku pg
  ActiveRecord::Base.connection.execute(sql)
end

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...