2010-08-19 45 views
1

我希望每次用户通过显式登录进入我的网站时都要增加login_count属性,或记住我登录。目前Authlogic只会增加每个显式登录的login_count。有没有其他人做过这件事,或者是否有人知道在插件内部如何定制这个内容?使用Authlogic递增login_count

+0

你能描述为什么你需要这个功能吗? – 2010-08-19 16:35:24

+0

后端分析。跟踪网站的访问情况 - 无论我为什么需要此功能,我都关心我如何才能做到这一点。 – scott 2010-08-19 16:58:12

回答

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代码,这应该工作。让我知道这是否适合你

+0

这没有,但我不认为是你的代码的结果。出于某种原因,我的Authlogic系统在整个会话中快速递增login_count。不知道为什么,但我找到了解决整个问题的方法。非常感谢您的帮助。 – scott 2010-08-20 14:16:08

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_countusers表。

+0

当用户在站点上移动页面时,这是否也会增加计数器? – scott 2010-08-19 17:20:29

+0

是的,它会的。我读错了你的要求。我会用正确的答复更新答案。 – 2010-08-19 17:23:21

+0

谢谢你的回复:) – scott 2010-08-19 17:50:18