2016-10-28 41 views
0

我在一個名爲users的表中設置一列名爲if_login。當我執行sign_in路徑時,我使用方法user_sign_in?將列if_login的值設置爲1.如何修改devise中的代碼以將列if_login設置爲0?如何在數據庫中設置一列用戶sign_out與設計

這裏是當EXCUTE「sign_in」路徑,該方法將設置用戶的「if_login」值= 1
if user_signed_in? 
    @user.update(if_login:1) 
end 
@user.save 
+0

添加方法,您需要提供一些代碼,如果你無法正確解釋問題,否則人們將無法幫助你。 –

+0

你說得對。謝謝 – Hitcker

回答

0

你應該在ApplicationController中

class ApplicationController < ActionController::Base 
    private 

    def after_sign_out_path_for(resource_or_scope) 
    # here write your code for the update your if_login 
    root_path 
    end 
end 
+0

謝謝first.I在ApplicationController是這樣做的:'current_user.update(if_login:0)'。但是,有一個錯誤'未定義的方法'更新爲零:NilClass',我認爲,執行'after_sign_out_path_for'方法,current_user將會丟失,我該如何保存它? – Hitcker