ref: master
vendor/plugins/kandadaboggu-vote_fu/lib/models/vote.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
class Vote < ActiveRecord::Base scope :for_voter, -> *args { where "voter_id = ? AND voter_type = ?", args.first.id, args.first.class.base_class.name } scope :for_voteable, -> *args { where "voteable_id = ? AND voteable_type = ?", args.first.id, args.first.class.base_class.name } scope :recent, -> *args { where "created_at > ?", (args.first || 2.weeks.ago).to_s(:db) } scope :descending, -> { order "created_at DESC" } # NOTE: Votes belong to the "voteable" interface, and also to voters belongs_to :voteable, :polymorphic => true belongs_to :voter, :polymorphic => true attr_accessible :vote, :voter, :voteable # Uncomment this to limit users to a single vote on each item. #validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id] end |