有没有办法返回当前登录的设计用户的数量? [英] Is there a way to return the number of devise users currently logged in?
问题描述
Rails 3.1
gem'devise','〜> 1.4'
gem'dm-devise','〜> 1.5'
with:Database Authenticatable
我正在寻找ruby代码。
由于所有与登录有关的信息都在会话中处理,所以开箱即用的方法并不简单。我建议在ApplicationController中做一些事情来管理这些信息。
我们在许多应用程序中使用了before_filter来跟踪每个页面请求的非常具体的信息。你可以做一些类似的操作,跟踪他们打到什么页面,打他们的位置,以及他们是谁。
然后确定登录的用户将是简单的确定多长时间之前他们的最后一页加载将不得不让他们计数为登录,然后根据这些选择您的视图表。
MyPageView.select([DISTINCT user WHERE created_at??,my_threshold_time])会给你不同的用户。
Is there a way to figure out how many users are actively logged into a rails app using devise?
Rails 3.1
gem 'devise', '~> 1.4' gem 'dm-devise', '~> 1.5'
with : Database Authenticatable
I am looking for ruby code specifically.
Since all of the information related to being logged in is handled in the session, there's no simple way out of the box. I would recommend doing something in ApplicationController to manage this information.
We use a before_filter in a number of our applications to track very specific information about each page request. You could do something similar to track what page they hit, when they hit it, and who they were.
Then determining logged in users would be as simple as determining how long ago their last page load would have to be for them to count as logged in, then select on your table of views based on that. Something like
MyPageView.select(["DISTINCT user WHERE created_at > ?", my_threshold_time]) would give you the distinct users.
这篇关于有没有办法返回当前登录的设计用户的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!