jmckible / hit_it

Track hits of ActiveRecord models

This URL has Read+Write access

hit_it /
name age message
file .gitignore Loading commit data...
file MIT-LICENSE
file README.rdoc
file Rakefile
directory generators/
file init.rb
directory lib/
directory test/
README.rdoc

hit_it

Tracks the hits (views) of assets.

Installation

  ruby script/plugin install git://github.com/jmckible/hit_it.git
  ruby script/generate hit_it_migration
  rake db:migrate

How it works

Add to an ActiveRecord model like so:

  class Page < ActiveRecord::Base
    track_hits
  end

Any time you’d like to remember a hit, just load an instance and fire away. Say, within a controller:

  def show
    @page = Page.find params[:id]
    @page.hit!
  end

Granularity

Right now this only works on a monthly basis. There’s a row in the hit table for every object x every month.

Sums

Here are some things you can do:

  @page.hits.sum(:count)
  @page.hits.for(2009, 1).sum(:count)

Author