forked from ryanto/acts_as_votable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vote.rb
29 lines (20 loc) · 731 Bytes
/
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
24
25
26
27
28
require 'acts_as_votable/helpers/words'
module ActsAsVotable
class Vote < ::ActiveRecord::Base
include Helpers::Words
if Rails.version.to_i < 4
attr_accessible :votable_id, :votable_type,
:voter_id, :voter_type,
:votable, :voter,
:vote_flag
end
belongs_to :votable, :polymorphic => true, :touch => true
belongs_to :voter, :polymorphic => true, :touch => true
scope :up, -> { where vote_flag: true }
scope :down, -> { where vote_flag: false }
scope :for_type, lambda{ |klass| where(:votable_type => klass) }
scope :by_type, lambda{ |klass| where(:voter_type => klass) }
validates_presence_of :votable_id
validates_presence_of :voter_id
end
end