Giter Site home page Giter Site logo

acts_as_viewable's Introduction

acts_as_viewable

A rather application specific gem for rails 2 which adds the ability to count views of your records.

When a model acts_as_viewable its instances are endowed with a view! method, which takes a single argument - an IP address. Invoking view! on a record records the viewing and increments a counter unless the IP in question has viewed this record within the last n minutes, where n can be specified in minutes via the :ttl option to acts_as_viewable (defaults to 60).

A rake task is provided for pruning view recordings.

Installation

config.gem 'acts_as_viewable'

$ rake gems:install
$ ./script/generate acts_as_viewable
$ rake db:migrate

Example

class Foo < ActiveRecord::Base
	acts_as_viewable :ttl => 60 * 24
end

class FoosController < ActionController::Base
	def show
		@foo = Foo.find(params[:id])
		@foo.view!(request.remote_ip)
		@total_viewings_for_all_time = @foo.views
		@records_of_viewings = @foo.viewings
		@twelve_most_viewed_foos_of_all_time = Foo.most_viewed(12)
	end
end

To delete viewing records greater than 10 days old.

$ rake acts_as_viewable:delete_old_records[10]

This will not effect the total viewings of any record.

Copyright

Copyright (c) 2010 iorum design & technology consultants. See MIT-LICENSE for further details.

acts_as_viewable's People

Contributors

al avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

acts_as_viewable's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.