What is the best way to solve this problem:
If you have a model - say Vote, and there are votes for various
categories of things such as comments, links, etc: What is the best
way to implement this? Is it best to create a model/database for each
type of vote (comment_votes, news_votes, etc_votes), tag each vote
with a vote_type parameter, or maybe do something with polymorphism.
Additionally how does that implementation affect how would you go
about saying something like user.comment_votes or user.news_votes the
user has_many of each of these types. I hope that makes sense and
thanks for your ideas.
This seems to me to be a little muddy. I suggest that you start with
what you are voting on, say an issue or better yet a proposal. Then you
have a voter model, and finally a ballot model. So a particular voter's
ballot is related to a specific proposal.
Class Voter < ActiveRecord::Base
Class Proposal < ActiveRecord::Base
Class Ballot < ActiveRecord::Base
The voter model/table contains all of your identity and eligibility
criteria. The proposal model/table contains all of the data relating to
a specific issue, including its type or class if this is a singleton
attribute, or you can hang a proposal_classifications model off of
proposals if you require N type attributes (likewise comments or notes).
The ballot contains the voter's choice on the issue plus whatever
ancillary data you desire (date and time cast, method of voting, place
of voting, ip address, etc.)
You validate the uniqueness of a ballot (one per voter per proposal) in
the Ballot model.