trustieforge/app/helpers/praise_tread_helper.rb

30 lines
880 B
Ruby

module PraiseTreadHelper
#added by william
def is_praise_or_tread(object,user_id)
@obj_type = object.class
@obj_id = object.id
@is_praise = PraiseTread.find_by_sql("select praise_or_tread from praise_treads where user_id=#{user_id} and " +
"praise_tread_object_type='#{@obj_type}' and praise_tread_object_id=#{@obj_id}")
return @is_praise
end
#end
def get_praise_num(object)
@obj_type = object.class
@obj_id = object.id
@record = PraiseTreadCache.find_by_object_id_and_object_type(@obj_id,@obj_type)
if @record
# case flag
# when 1
# return @record.praise_num.nil? ? 0 : @record.praise_num
# when 0
# return @record.tread_num.nil? ? 0 : @record.tread_num
# end
return (@record.praise_num.to_i-@record.tread_num.to_i)
else
return 0
end
end
end