h1. HasViewCount h3. Adds a polymorphic association that allows any model to have a unique visitor count (based on IP address) h2. Installation
script/plugin install git://github.com/citrus/has_view_count.git
- or -
git submodule add git://github.com/citrus/has_view_count.git vendor/plugins/has_view_count
script/generate has_view_count
rake db:migrate
restart mongrel
_This will generate_
db/migrate/XXXXXXXXXXXXXX_has_view_count_migration.rb
app/models/view_count.rb
***************************************************************************
h2. Example
h4. Model:
class Post < ActiveRecord::Base
has_view_count
end
h4. Controller:
class PostsController < ApplicationController
after_filter :record_view_count, :only => :show
...
...
...
private
def record_view_count
@post.record_view_count(request.remote_ip, logged_in?) # use logged_in? if you have restful_authentication installed
end
end
_Copyright (c) 2009 Citrus Media Group / Spencer Steffen, released under the MIT license_