Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9228325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:17:37+00:00 2026-06-18T05:17:37+00:00

Update I ended up with a dedicated statistics model and table that gets data

  • 0

Update

I ended up with a dedicated statistics model and table that gets data with the use of the whenever gem . Look at my own answer for more details.

Orginal question

In my ruby on rails application I want to make a chart in my admin pages that displays the numbers of users on my site over time.

The chart should display the numbers of users on all dates the last year.

If there comes in new users the curve goes up and if users get deleted it goes down.

This would be the JSON result I am after.

[
    {
        "date": "23-01-2013",
        "users": 3201
    },
    {
        "date": "24-01-2013",
        "users": 3451
    },
    {
        "date": "25-01-2013",
        "users": 4351
    },
    {
        "date": "26-01-2013",
        "users": 3950
    },
    {
        "date": "27-01-2013",
        "users": 4150
    }
]

I have considered making a statistics model and add before_create and before_destroy filters in my user model that updates the statistics model.

Is there a better way and maybe a gem that does this? I guess I have not found the solution because I don’t know what this is called.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:17:39+00:00Added an answer on June 18, 2026 at 5:17 am

    The solution was to make a statistics model and table in the database. I use the whenever gem to run a write_stats method on the statistics model every day. It might be a bit heavy, but it gives me great data to pull from.

    Here’s the schedule.rb for the whenever gem

    set :output, "#{path}/log/cron.log"
    
    every :day, at: "11:58 PM" do
      runner "Statistics.write_count"
    end
    

    And here’s the Statistics model

    class Statistics < ActiveRecord::Base
      def self.write_count
        stats = Statistics.new
        stats.users = User.count
        stats.save!
      end
    end
    

    The statistics table has timestamps, so it makes queries easy.

    Here is one

    @stats = Statistics.where(created_at: (Time.now.years_ago(1)..Time.now))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE UPI_ATTRIBUTE SET SITE_INC ='0' WHERE USER_PROFILING_NAME IN ('CAR_IMPLICIT','CAR_EXPLICIT') Above is my query that
UPDATE 6/21/12 I have a form in rails that is working similar to an
UPDATE: I ended up giving up and added GHUnit to my project instead. I
I need to write a report that generates summary totals against a table with
I am maintaining an Android app that people use to display strings in various
UPDATE I ended up fixing the issues with MGSplitViewController, so I am now using
Is a method such as OnClosed(EventArgs e) called? Update Ended up using code from
Update: We ended up using a process very much like this schema (thanks to
Update: Is there a way to achieve what I'm trying to do in an
update: I mistyped 2 variables...so embarrassing. thanks everyone for the effort! sorry i find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.