Jeff Rossi
Jeff Rossi

Reputation: 189

Devise allow email uniqueness within scope

I'm in the process of upgrading a large project from rails 2 to rails 3, as a part of that upgrade I'm replacing a very old restful_athentication with devise.

The problem I'm having is that in the existing users table emails are validated like this.

validates_uniqueness_of :email, :scope => :account_id # No dupes within account

So if I add the index from the migration to add devise to users it WILL fail.

Is there a way that I can use

add_index :users, [:email,:account_id]

And have devise work properly?

Upvotes: 2

Views: 1965

Answers (1)

Jeff Rossi
Jeff Rossi

Reputation: 189

I managed to get this working on my own, I added the following to config/initializer/devise.rb

config.authentication_keys = [ :email , :account_id]

Upvotes: 3

Related Questions