@ -6,38 +6,46 @@ class PraiseTreadController < ApplicationController
def praise_plus
@obj = nil
# @is_in_list = nil
if @pt = PraiseTread . where ( " praise_tread_object_id=? and praise_tread_object_type=? and user_id=? " , @obj_id , @obj_type . to_s , User . current . id ) . first
end
if request . get?
@obj_id = params [ :obj_id ]
@obj_type = params [ :obj_type ]
@horizontal = params [ :horizontal ] . downcase == " false " ? false :true
#@horizontal = params[:horizontal].downcase == "false" ? false :true
@obj = find_object_by_type_and_id ( @obj_type , @obj_id )
unless @obj . author_id == User . current . id
praise_tread_plus ( @obj_type , @obj_id , 1 )
end
@user_activity_id = params [ :user_activity_id ] if params [ :user_activity_id ]
@type = params [ :type ] if params [ :type ]
end
end
def praise_minus
@obj = nil
if request . get?
@obj = params [ :obj ] # 传的是对象, 最后变成id了
#@obj = params[:obj] # 传的是对象, 最后变成id了
@obj_id = params [ :obj_id ]
@obj_type = params [ :obj_type ]
#首先更新praise_tread 表 删除关注记录
@pt = PraiseTread . find_by_user_id_and_praise_tread_object_id_and_praise_tread_object_type ( User . current . id , @obj , " user " )
@pt . delete
#@pt = PraiseTread.find_by_user_id_and_praise_tread_object_id_and_praise_tread_object_type(User.current.id,@obj,"user")
@pt = PraiseTread . where ( " praise_tread_object_id=? and praise_tread_object_type=? and user_id=? " , @obj_id , @obj_type . to_s , User . current . id ) . first
@pt . delete if ! @pt . nil?
#再更新praise_tread_cache表 使相应的记录减1 当为0时删除
@ptc = PraiseTreadCache . find_by_object_id( @obj )
@ptc . minus ( 1 )
@ptc = PraiseTreadCache . where( " object_id=? and object_type=? " , @obj_id , @obj_type . to_s ) . first
@ptc . minus ( 1 ) if ! @ptc . nil?
if @ptc . praise_num == 0
@ptc . delete
end
end
@obj = User . find_by_id ( @obj )
#@obj = User.find_by_id(@obj)
@obj = find_object_by_type_and_id ( @obj_type , @obj_id )
@user_activity_id = params [ :user_activity_id ] if params [ :user_activity_id ]
@type = params [ :type ] if params [ :type ]
respond_to do | format |
format . html
format . js
end
end
@ -48,7 +56,7 @@ class PraiseTreadController < ApplicationController
if request . get?
@obj_id = params [ :obj_id ]
@obj_type = params [ :obj_type ]
@horizontal = params [ :horizontal ] . downcase == " false " ? false :true
#@horizontal = params[:horizontal].downcase == "false" ? false :true
@obj = find_object_by_type_and_id ( @obj_type , @obj_id )
unless @obj . author_id == User . current . id
praise_tread_plus ( @obj_type , @obj_id , 0 )