Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 328
Jay Avatar asked Aug 17 '11 18:08

Jay


3 Answers

= 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
like image 62
Moin Haidar Avatar answered Oct 21 '22 09:10

Moin Haidar


Look in the config/initializers/devise.rb. You can change the default authentication key, which by default is :email to be anything you want, for example:

config.authentication_keys = [ :username ]

like image 38
eugen Avatar answered Oct 21 '22 09:10

eugen


Please find the instructions here

like image 2
rookieRailer Avatar answered Oct 21 '22 09:10

rookieRailer