2013-08-08 17:01:56 +08:00
|
|
|
class PraiseTreadCache < ActiveRecord::Base
|
|
|
|
attr_accessible :object_id,:object_type,:praise_num,:tread_num
|
2016-09-23 16:44:49 +08:00
|
|
|
belongs_to :object, :polymorphic => true
|
|
|
|
|
2013-08-12 14:50:54 +08:00
|
|
|
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
|
2013-08-08 17:01:56 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def minus(num)
|
|
|
|
self.update_attribute(:praise_num, self.praise_num.to_i - num)
|
|
|
|
end
|
|
|
|
end
|