From f06dfc025ac2e5b7fdfe6253db505a95021498be Mon Sep 17 00:00:00 2001 From: Absurdon Date: Sun, 2 Jul 2017 17:14:07 +0200 Subject: [PATCH] show count for users signed in the last 30 days on users page --- app/models/user.rb | 2 ++ app/views/users/index.html.erb | 1 + db/migrate/20170702150454_add_lastvisit_index_to_users.rb | 5 +++++ 3 files changed, 8 insertions(+) create mode 100644 db/migrate/20170702150454_add_lastvisit_index_to_users.rb diff --git a/app/models/user.rb b/app/models/user.rb index 9cefd2b..c9349c6 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -99,6 +99,8 @@ class User < ActiveRecord::Base :conditions => "bans.id IS NOT NULL" scope :idle, :conditions => ["lastvisit < ?", 30.minutes.ago.utc] + scope :lately, + :conditions => ["lastvisit > ?", 30.days.ago.utc] before_validation :update_password diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 6f890e1..2baba4f 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,4 +1,5 @@

Listing Users

+

<%= User.lately.count %> players have signed in within the past 30 days.

Search for users by name or Steam ID:

diff --git a/db/migrate/20170702150454_add_lastvisit_index_to_users.rb b/db/migrate/20170702150454_add_lastvisit_index_to_users.rb new file mode 100644 index 0000000..6729c1e --- /dev/null +++ b/db/migrate/20170702150454_add_lastvisit_index_to_users.rb @@ -0,0 +1,5 @@ +class AddLastvisitIndexToUsers < ActiveRecord::Migration + def change + add_index :users, :lastvisit + end +end