我希望每次用户通过显式登录进入我的网站时都会增加login_count属性,或者记住我登录。目前,Authlogic仅在每次显式登录时增加login_count。有没有其他人这样做过,或者有人知道在插件里面自定义这个吗?
答案 0 :(得分:0)
向before_filter
添加ApplicationController
以增加计数器。
class ApplicationController < ActionController::Base
before_filter :increment_visit_count
private
def increment_visit_count
User.increment_counter(:visit_count, current_user.id) if current_user
end
end
注意:此解决方案需要visit_count
表中的新列users
。
答案 1 :(得分:0)
按如下方式更新您的用户会话类:
class UserSession < Authlogic::Session::Base
def persist_by_cookie
r = super
User.increment_counter(:login_count, unauthorized_record.id) if r
r
end
end
注意:我还没有测试过这段代码。根据Authlogic代码,这应该工作。如果这对您有用,请告诉我