2011-07-17 18 views
-1

我有一個客戶設計控制器,我想設置我的註冊操作,當用戶登錄時用戶登錄和離線時將用戶狀態更新爲在線。我有自定義設計更新登錄和登出時的用戶屬性

def signin 
super 
end 

我想在登錄時將用戶狀態屬性更新爲在線登錄和離線。請在這裏尋求幫助

回答

0

您可能會丟失attr_accesible申報表用戶的「狀態」屬性?

-2

您可以使用devise中提供的after_sign_in_path_for和after_sign_out_path_for鉤子。只需重寫ApplicationController中的這些方法即可。例如。

class ApplicationController < ActionController::Base 
    private 

    def after_sign_in_path_for(resource_or_scope) 
    #update user status to online 
    root_path 
    end 

    def after_sign_out_path_for(resource_or_scope) 
    #update user status to offline 
    root_path 
    end 
end 

此處瞭解詳情:devise wiki

+0

我試過了,我無法使update_attributes正常工作。這裏有一個簡單的幫助 – Uchenna

+0

你能告訴我你的代碼嗎?你的更新代碼被調用了嗎?有錯誤嗎? –