-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
106 lines (70 loc) · 2.83 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
= acts_as_viewed
The ultimate viewing system for ActiveRecord models.
This plugin allow to keep the view count of objects. The views are only counted one time by IP address or User. The viewer class can be changed from User to whatever you want.
Highly flexible and configurable, while easy to use with the defaults.
Creates all the needed associations for easy access to everything.
Comes complete with the needed migrations code to make it easy to add to any project.
Note: the code are based in the excellent acts_as_rated plugin.
== Features
* Keep the view count to any model
* Optionally add the views field to the viewed objects to optimize speed
* Can work with the added views field or just using direct SQL count calls
* Use any model as the viewer (defaults to User)
* Find objects by viewer
* Check if an object is viewed by a specific viewer.
== Basic Details
Install
* script/plugin install svn://rubyforge.org/var/svn/acts-as-viewed/trunk
* gem install - <b>coming soon</b>
Rubyforge project
* http://rubyforge.org/projects/acts-as-viewed
RDocs
* http://acts-as-viewed.rubyforge.org
Subversion
* svn://rubyforge.org/var/svn/acts-as-viewed
Agile Web Development directory
* http://www.agilewebdevelopment.com/plugins/acts_as_viewed
My blog with some comments about the plugin
* http://www.do2.com.ar
BUGS & FEEDBACK
===============
Bug reports (as well as patches) and feedback are very welcome. Please send it to
== TODO
* Test
== Example of usage:
=== Simple rating system
class Movie < ActiveRecord::Base
acts_as_viewed
end
In a controller:
bill = User.find_by_name 'bill'
batman = Movie.find_by_title 'Batman'
toystory = Movie.find_by_title 'Toy Story'
batman.view request.remote_ip, bill
toystory.view request.remote_ip, bill
batman.view_count # => 1
=== Migration
See also the detailed documentation for the <tt>acts_as_viewed</tt> method on how to declare it, and the rest of the documentation for how to generate the migration columns/files and how to use it.
class AddViewingTables < ActiveRecord::Migration
def self.up
ActiveRecord::Base.create_viewings_table
# Movies table has the columns for the viewings added while it's created
create_table(:movies) do |t|
t.column :title, :text
Movie.generate_viewings_columns t
end
# Movies table has the columns for the viewings added, but after the fact, using ALTER TABLE calls.
# Usually used if the model already exist and we want to add the viewings after the fact
create_table(:movies) do |t|
t.column :title, :text
end
Movie.add_viewings_columns
end
def self.down
# Remove the columns we added
Movie.remove_viewings_columns
drop_table :movies rescue nil
ActiveRecord::Base.drop_viewings_table
end
end