我在一個名爲users
的表中設置一列名爲if_login
。當我執行sign_in
路徑時,我使用方法user_sign_in?
將列if_login
的值設置爲1.如何修改devise
中的代碼以將列if_login
設置爲0?如何在數據庫中設置一列用戶sign_out與設計
if user_signed_in?
@user.update(if_login:1)
end
@user.save
我在一個名爲users
的表中設置一列名爲if_login
。當我執行sign_in
路徑時,我使用方法user_sign_in?
將列if_login
的值設置爲1.如何修改devise
中的代碼以將列if_login
設置爲0?如何在數據庫中設置一列用戶sign_out與設計
if user_signed_in?
@user.update(if_login:1)
end
@user.save
你應該在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
謝謝first.I在ApplicationController是這樣做的:'current_user.update(if_login:0)'。但是,有一個錯誤'未定義的方法'更新爲零:NilClass',我認爲,執行'after_sign_out_path_for'方法,current_user將會丟失,我該如何保存它? – Hitcker
添加方法,您需要提供一些代碼,如果你無法正確解釋問題,否則人們將無法幫助你。 –
你說得對。謝謝 – Hitcker