问题描述
我想通过Rails 2.3.8应用程序记录用户活动.我不在乎活动是什么,只是任何给定用户最后一次在网站上进行任何操作,包括查看页面,发表评论,登录等.
I want to log the user activity through my Rails 2.3.8 application. I don't care what the activity is, just the last time any given user did anything on the site, including viewing pages, commenting, logging in, etc.
我能想到的一种方法是在用户模型中的last_active DateTime属性上创建并根据用户的活动不断更新此属性(或可能利用了updated_at列).我可以在每个控制器的每个动作上放置一个after_filter来调用更新方法,但这似乎很麻烦而且过多.肯定有更好的办法.观察员会工作吗?如果是这样-怎么办?我在这里缺少Rails内置的东西吗?
One method that I can think of is creating at last_active DateTime attribute in the user model and constantly updating this attribute based on a user's activity (or possibly taking advantage of the updated_at column). I could put an after_filter on every action of every controller to call an update method, but this seems hacky and excessive. There must be a better way. Would an observer work? If so - how? Is there something built-in to Rails that I'm missing here?
谢谢!
推荐答案
将after_filter
放在ApplicationController
上.您可以根据需要使用skip_after_filter
在其他控制器中将其关闭.
Put your after_filter
on the ApplicationController
. You can turn it off in other controllers with skip_after_filter
as needed.
这篇关于记录活动的最佳方法(Ruby on Rails)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!