So I\'m implementing an up/down voting mechanism for which I\'m generating a model. So far I understand that a video (what will be voted on) has one vote_count, and vote_cou
It may be easier to track the votes as independent records, such as this:
class VideoVote < ActiveRecord::Base
belongs_to :user
belongs_to :video
end
class User < ActiveRecord::Base
has_many :video_votes
has_many :voted_videos,
:through => :video_votes,
:source => :video
end
class Video < ActiveRecord::Base
has_many :video_votes,
:counter_cache => true
has_many :voted_users,
:through => :video_votes,
:source => :user
end
If you have people voting up and down, you will need to track the net vote total somehow. This can be tricky, so you may want to look for a voting plugin.
Am I missing something here? Why not assign a netVoteTally
as a property of Videos
. Initialize it to zero when video.new
is called and have incNetVideoTally
and decNetVideoTally
methods that are accessible outside the video method? Just my $0.02.