2014-01-23 1 views
0

나는이 세 가지 궁리 :devise gem을 사용하여 특정 경로로 로그 아웃 할 수 없습니까?

내가 application_controller.rb

def after_sign_in_path_for(authorize) 
    auth_main_path 
end 

def after_sign_out_path_for(authorize) 
    new_authorize_session_path 
end 
def after_sign_in_path_for(employe) 
    employee_emain_path 
end 

def after_sign_out_path_for(employe) 
    new_employe_session_path 
end 
def after_sign_in_path_for(hr) 
    hrs_hhome_path 
end 
def after_sign_out_path_for(hr) 
    new_hr_session_path 
end 

sign_out 버튼 application.html.erb 코드 :authorize로 로그인하면

devise_for :hrs 
devise_for :employes 
devise_for :authorizes 

이다 : 그것은 작동

<%= link_to "SIGNOUT", destroy_authorize_session_path, :method => :delete ,:data => { confirm: 'Are you sure?' } %> 

여기까지 완벽하게,하지만 내가 컨트롤러를 추가하자마자 그녀의 두 유증은 오류를 내가 버튼으로 변경해야합니까

을 제공합니다 그래서 그것을 destroy the session for the current_session 내가 signed in:hr로, 다음 signout 클릭은 지정된 경로로 렌더링해야합니다. 다른 장치 모델에도 똑같이 적용해야합니다. 내가 sign_out 버튼을 누르면 전 직원 또는 시간으로 log_in 때

ERROR

나는 오류가 발생합니다. 나는 그것이`내가 해야하는 변화에 대한 employee_session을 파기해야한다.

감사합니다.

+0

어떤 오류입니까? 질문에 답장 해주십시오. 로그 아웃이 작동합니까? –

+0

예 현재 로그 아웃이 작동합니다. 하지만 나는 2 가지 이상을 가지고있다. –

+0

오류가 발생했을 때 게시하십시오. –

답변

1

로그인 한 사용자의 올바른 경로를 반환하는 방법을 항상 만들 수 있습니다.

예를 들어, 사용자와 ApplicationController에 당신이 당신의 HTML에서 그런

def sign_out_path 
if hr_signed_in? 
    destroy_hr_session_url 
elsif employe_signed_in? 
    destroy_employe_session_url 
else 
    destroy_authorize_session_url 
end 
end 

처럼 뭔가를 현재 사용자에 대한 올바른 로그 아웃 경로를 얻을 수있는 방법을 추가하는 대신 경로의이 방법을 사용할 수 있습니다.

<%= link_to "SIGNOUT", sign_out_path, :method => :delete ,:data => { confirm: 'Are you sure?' } %> 

실제로 로그인 한 사용자가 있는지 확인하는 방법을 추가하고 로그 아웃 링크 만 표시해야합니다.

관련 문제