已点过赞的动态显示”已赞“

This commit is contained in:
cxt 2016-01-18 15:12:47 +08:00
parent df57b13ce0
commit 9cabb0248a
2 changed files with 13 additions and 4 deletions

View File

@ -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

View File

@ -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? %>
<a href="<%= praise_tread_praise_plus_path({:obj_id=>activity.id,:obj_type=>activity.class,:user_activity_id=>user_activity_id,:type=>type })%>" data-remote="true" class="<%=type == 'reply'? 'fr' : 'ml15' %> likeButton" title="点赞" >
<span class="likeText">赞</span><span class="likeNum"><%= get_praise_num(activity) > 0 ? "#{get_praise_num(activity)}" : "" %></span></a>
<span class="likeText">赞</span>
<% num = get_praise_num(activity) %>
<span class="likeNum"><%= num > 0 ? "#{num}" : "" %></span>
</a>
<% else %>
<a href="<%= praise_tread_praise_minus_path({:obj_id=>activity.id,:obj_type=>activity.class,:user_activity_id=>user_activity_id,:type=>type })%>" data-remote="true" class="<%=type == 'reply'? 'fr' : 'ml15' %> likeButton" title="取消点赞" >
<span class="likeText">赞</span><span class="likeNum"><%= get_praise_num(activity) > 0 ? "#{get_praise_num(activity)}" : "" %></span></a>
<span class="likeText">已赞</span>
<% num = get_praise_num(activity) %>
<span class="likeNum"><%= num > 0 ? "#{num}" : "" %></span>
</a>
<% end %>