0
ユーザがサインインまたはサインアウトするたびに、自分のユーザテーブルのステータス属性を「オンライン」または「オフライン」に変更したい。 私は、関連する方法にupdate_attributeを追加することによって、自分自身のセッションコントローラを作成しました:私は未定義のメソッドのエラーを取得するRails 3 + Devise:サインインとサインアウト時にデータベース属性を更新する
class SessionsController < Devise::SessionsController
def sign_out_and_redirect(resource_or_scope)
current_user.update_attribute(:status, "Offline")
scope = Devise::Mapping.find_scope!(resource_or_scope)
Devise.sign_out_all_scopes ? sign_out : sign_out(scope)
redirect_for_sign_out(scope)
end
def redirect_for_sign_out(scope)
redirect_to after_sign_out_path_for(scope)
end
def sign_in_and_redirect(resource_or_scope, *args)
options = args.extract_options!
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource = args.last || resource_or_scope
if warden.user(scope) == resource
expire_session_data_after_sign_in!
else
sign_in(scope, resource, options)
end
current_user.update_attribute(:status, "Online")
redirect_for_sign_in(scope, resource)
end
def redirect_for_sign_in(scope, resource)
redirect_to stored_location_for(scope) || after_sign_in_path_for(resource)
end
end
と、次のために:
Devise.sign_out_all_scopes
expire_session_data_after_sign_in!
は、私はこれをどのように修正するのですか?
私が唯一持っている最初の未定義のメソッド削除:
sign_out(scope)
をして、それが出て署名するために動作します。しかし、私は式の署名を削除したくありません。
どうすればいいですか?ユーザーのオンラインステータスを追跡する別の方法がありますか?
申し訳ありませんが、私の問題は解決したと思っていましたが、数回しか働いていませんでした... しばらくしてから、新しいユーザーが作成された後、サインインまたはサインアウト – Max