Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Home

turadg edited this page · 3 revisions
Clone this wiki locally

Welcome to the thumbs_up wiki!

Examples

Permission to vote more than once

  # 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 }

Permission to vote once daily

(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
Something went wrong with that request. Please try again.