Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use different authentication_keys for two devise models?

Now I have one devise model, which uses email as authentication_key.

I want to add one new devise model, which uses student_id as authentication_key.

Some guide tells me to modify the configuration

"config.authentication_keys = [ :email ]" by replacing the :email with :student_id.

After modification, the first model login always fails, so I think I have to indicate different authentication_keys for the two models separately.

How should I do?

like image 353
Roy Avatar asked Jan 08 '11 08:01

Roy


1 Answers

You will have to declare inside your models which are the authenitcation keys, rather than inside the devise.rb file.

class model1 < ActiveRecord::Base  devise :database_authenticatable, :rememberable, :trackable, :authentication_keys => [:email] 

and for your second model

class model2 < ActiveRecord::Base  devise :database_authenticatable, :rememberable, :trackable, :authentication_keys => [:studentid] 

also make sure that you comment out from devise.rb the config.authentication_keys settings

like image 186
Dimitris Avatar answered Oct 09 '22 11:10

Dimitris