Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: e80b795392
Fetching contributors…

Cannot retrieve contributors at this time

43 lines (28 sloc) 1.086 kb


Maintains period fields on any counter column in your database


sudo gem install periodic_counter

Create columns

You should already have a counter column defined that is being incremented by something (let's call the column X).

Define period columns using this format: X_last_week or X_last_6_hours.

The period name should follow the format of ActiveSupport's time extensions.

Also add an X_data varchar column with a length of 2048.

Create configuration

Create a file, config/counters.yml:

  - my_counter

The plugin assumes that the config directory also houses your database.yml file.

Create cron entry

Add the following command to your crontab at a period of your choosing:

cd /path/to/your/app && RAILS_ENV=production periodic_counter
Jump to Line
Something went wrong with that request. Please try again.