Sha256: 569a891e4ab9e448dcaeefb2f5eb13fbcde61a25fa836f319a6983903133b199

Contents?: true

Size: 832 Bytes

Versions: 6

Compression:

Stored size: 832 Bytes

Contents

class Vote < ActiveRecord::Base

  scope :for_voter, lambda { |*args| where(["voter_id = ? AND voter_type = ?", args.first.id, args.first.class.base_class.name]) }
  scope :for_voteable, lambda { |*args| where(["voteable_id = ? AND voteable_type = ?", args.first.id, args.first.class.base_class.name]) }
  scope :recent, lambda { |*args| where(["created_at > ?", (args.first || 2.weeks.ago)]) }
  scope :descending, lambda { order("created_at DESC") }

  belongs_to :voteable, :polymorphic => true
  belongs_to :voter, :polymorphic => true

  attr_accessible :vote, :voter, :voteable if ActiveRecord::VERSION::MAJOR < 4

<% if options[:unique_voting] == true %>
  # Comment out the line below to allow multiple votes per user.
  validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id]
<% end %>
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
thumbs_up-0.6.10 lib/generators/thumbs_up/templates/vote.rb
thumbs_up-0.6.9 lib/generators/thumbs_up/templates/vote.rb
thumbs_up-0.6.8 lib/generators/thumbs_up/templates/vote.rb
thumbs_up-0.6.7 lib/generators/thumbs_up/templates/vote.rb
thumbs_up-0.6.6 lib/generators/thumbs_up/templates/vote.rb
thumbs_up-0.6.5 lib/generators/thumbs_up/templates/vote.rb