Module: YeshuaCrm::ActsAsViewed::Viewed

Defined in:
lib/yeshua_crm/acts_as_viewed/rcrm_acts_as_viewed.rb

Overview

acts_as_viewed

Adds views count capabilities to any ActiveRecord object. It has the ability to work with objects that have or don’t special fields to keep a tally of the viewings for each object. In addition it will by default use the User model as the viewer object and keep the viewings per-user. It can be configured to use another class. The IP address are used to not repeat views from the same ip. Only one view are count by user or IP.

Special methods are provided to create the viewings table and if needed, to add the special fields needed to keep per-objects viewings fast for access to viewed objects. Can be easily used in migrations.

Example of usage:

class Video < ActiveRecord::Base
  acts_as_viewed
end

In a controller:

bill = User.find_by_name 'bill'
batman = Video.find_by_title 'Batman'
toystory  = Video.find_by_title 'Toy Story'

batman.view request.remote_addr, bill
toystory.view  request.remote_addr, bill

batman.view_count     # => 1

Defined Under Namespace

Modules: ClassMethods, ViewMethods Classes: ViewedError

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



55
56
57
# File 'lib/yeshua_crm/acts_as_viewed/rcrm_acts_as_viewed.rb', line 55

def self.included(base) #:nodoc:
  base.extend(ClassMethods)
end