Sha256: aac5dbfce099cf027b8235e110a9e3f2c8a8875bbed9f95d94ed2142df8a4ce4
Contents?: true
Size: 898 Bytes
Versions: 19
Compression:
Stored size: 898 Bytes
Contents
class Vote < ActiveRecord::Base scope :for_voter, lambda { |*args| where(["voter_id = ? AND voter_type = ?", args.first.id, args.first.class.name]) } scope :for_voteable, lambda { |*args| where(["voteable_id = ? AND voteable_type = ?", args.first.id, args.first.class.name]) } scope :recent, lambda { |*args| where(["created_at > ?", (args.first || 2.weeks.ago)]) } scope :descending, order("created_at DESC") belongs_to :voteable, :polymorphic => true belongs_to :voter, :polymorphic => true attr_accessible :vote, :voter, :voteable # Comment out the line below to allow multiple votes per user. validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id] after_create :update_counter_cache after_destroy :update_counter_cache private def update_counter_cache voteable.update_attribute(:votes_count, voteable.plusminus) end end
Version data entries
19 entries across 19 versions & 1 rubygems