2011-01-08 6 views
23

이제 전자 메일을 authentication_key로 사용하는 하나의 장치 모델이 있습니다.두 가지 모델에 대해 서로 다른 authentication_keys를 사용하는 방법은 무엇입니까?

student_id를 authentication_key로 사용하는 새 개발자 모델을 추가하고 싶습니다. 함께 이메일 : student_id를 대체하여 :

일부 가이드는 구성을

"[이메일] config.authentication_keys ="을 수정하는 나에게 말한다.

수정 후 첫 번째 모델 로그인은 항상 실패하므로 두 모델에 대해 서로 다른 authentication_keys를 별도로 지정해야한다고 생각합니다.

어떻게해야합니까?

답변

76

devise.rb 파일 대신 authenitcation 키인 모델 내부에서 선언해야합니다.

class model1 < ActiveRecord::Base 

devise :database_authenticatable, :rememberable, :trackable, :authentication_keys => [:email] 

와 두 번째 모델

또한
class model2 < ActiveRecord::Base 

devise :database_authenticatable, :rememberable, :trackable, :authentication_keys => [:studentid] 

당신이

+0

그레이트 config.authentication_keys 설정 devise.rb에서 주석 있는지 확인, 고마워요! – Roy

+2

로이, 대답이 적합한 경우 정답으로 표시하십시오 (일부 평판을 얻으 려합니다!). 많은 감사합니다! – Dimitris

+0

이것은 자신의 인증을 위해 Devise를 사용하는 Refinery CMS 꼭대기에있는 앱을 구현하면서 내 엉덩이를 저장했습니다. 감사! –

관련 문제