socialforge/app/models/praise_tread_cache.rb

18 lines
456 B
Ruby

class PraiseTreadCache < ActiveRecord::Base
attr_accessible :object_id,:object_type,:praise_num,:tread_num
belongs_to :object, :polymorphic => true
def plus(flag,num)
case flag
when 0
self.update_attribute(:tread_num, self.tread_num.to_i + num)
when 1
self.update_attribute(:praise_num, self.praise_num.to_i + num)
end
end
def minus(num)
self.update_attribute(:praise_num, self.praise_num.to_i - num)
end
end