Files
danbooru/app/models/post_vote.rb
r888888888 fad0ab7c93 fixes #2133
2014-04-16 17:43:34 -07:00

22 lines
494 B
Ruby

class PostVote < ActiveRecord::Base
class Error < Exception ; end
belongs_to :post
before_validation :initialize_user, :on => :create
validates_presence_of :post_id, :user_id, :score
validates_inclusion_of :score, :in => [1, -1]
attr_accessible :post_id, :user_id, :score
def score=(x)
if x == "up"
write_attribute(:score, 1)
elsif x == "down"
write_attribute(:score, -1)
end
end
def initialize_user
self.user_id = CurrentUser.user.id
end
end