From 9cabb0248a955797a2ca7b94872424ffd16ae7d2 Mon Sep 17 00:00:00 2001 From: cxt Date: Mon, 18 Jan 2016 15:12:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=B2=E7=82=B9=E8=BF=87=E8=B5=9E=E7=9A=84?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E6=98=BE=E7=A4=BA=E2=80=9D=E5=B7=B2=E8=B5=9E?= =?UTF-8?q?=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/praise_tread_controller.rb | 7 +++++-- app/views/praise_tread/_praise.html.erb | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index b99963e2f..291a71f26 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -24,7 +24,7 @@ class PraiseTreadController < ApplicationController end return end - #@horizontal = params[:horizontal].downcase == "false" ? false:true + @horizontal = params[:horizontal].downcase == "false" ? false:true if params[:horizontal] if @obj.respond_to?("author_id") author_id = @obj.author_id elsif @obj.respond_to?("user_id") @@ -127,6 +127,8 @@ class PraiseTreadController < ApplicationController @obj = Comment.find_by_id(id) when 'Journal' @obj = Journal.find_by_id(id) + else + @obj = nil end return @obj end @@ -143,7 +145,8 @@ class PraiseTreadController < ApplicationController # end #再创建或更新praise_tread_cache表 - @ptc = PraiseTreadCache.find_by_object_id_and_object_type(id,type) + #@ptc = PraiseTreadCache.find_by_object_id_and_object_type(id,type) + @ptc = PraiseTreadCache.where("object_id = ? and object_type = ?",id.to_i,type).first @ptc = @ptc.nil? ? PraiseTreadCache.new : @ptc @ptc.object_id = id.to_i @ptc.object_type = type diff --git a/app/views/praise_tread/_praise.html.erb b/app/views/praise_tread/_praise.html.erb index 4fd961251..63b57f8a6 100644 --- a/app/views/praise_tread/_praise.html.erb +++ b/app/views/praise_tread/_praise.html.erb @@ -1,7 +1,13 @@ <% if PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",activity.id,activity.class.to_s,User.current.id).empty? %> - <%= get_praise_num(activity) > 0 ? "(#{get_praise_num(activity)})" : "" %> + + <% num = get_praise_num(activity) %> + <%= num > 0 ? "(#{num})" : "" %> + <% else %> - <%= get_praise_num(activity) > 0 ? "(#{get_praise_num(activity)})" : "" %> + 已赞 + <% num = get_praise_num(activity) %> + <%= num > 0 ? "(#{num})" : "" %> + <% end %> \ No newline at end of file