forked from pilotcreative/vote_fu
-
Notifications
You must be signed in to change notification settings - Fork 75
Home
turadg edited this page Nov 18, 2012
·
3 revisions
Welcome to the thumbs_up wiki!
# One vote per user, unless editor role or higher
validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id],
message: "only one vote allowed",
unless: Proc.new { |vote| vote.voter.role? :editor }
(contributed in #54)
module ThumbsUp
module ActsAsVoter
module InstanceMethods
def voted_for_today?(voteable)
0 < Vote.where(
:voter_id => self.id,
:voter_type => self.class.base_class.name,
:voteable_id => voteable.id,
:voteable_type => voteable.class.base_class.name,
:day_created_at => DateTime.now.utc.midnight
).count
end
end
end
end