2014-01-23 38 views
0

我有三個色器件:無法使用devise gem註銷到特定路徑?

devise_for :hrs 
devise_for :employes 
devise_for :authorizes 

如果我在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是:

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

到這裏它的工作原理完美,但只要我爲ot添加控制器她的兩個色器件提示錯誤

我應該改變的按鈕是什麼使得它destroy the session for the current_session 如果我signed in:hr,然後點擊signout應該渲染到指定的路徑。同樣應該適用於其他設計模型。

錯誤

如果我按下按鈕sign_out我得到錯誤,當我log_in作爲僱員或小時。我想`如果我登錄爲員工,那麼它應該銷燬employee_session,因爲我應該做些什麼改變。

謝謝。

+0

什麼錯誤 - 請將其添加到您的問題。是否有任何註銷工作? –

+0

是的,當前登出的作品。但我還有2個設計。 –

+0

請發佈錯誤(s),當它們發生時 –

回答

1

您始終可以創建一個方法來爲登錄用戶返回正確的路徑。

例如,在你的ApplicationController中,你可以添加一個方法來獲取當前用戶的正確簽出路徑,像

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 

然後在你的HTML中,使用這種方法,而不是路徑。

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

你應該真的添加一個方法來檢查是否有用戶登錄,然後只顯示註銷鏈接。