首页课程讨论区动态的点赞

This commit is contained in:
cxt 2016-01-13 19:16:51 +08:00
parent b73aab1cf6
commit 093574ebef
4 changed files with 17 additions and 9 deletions

View File

@ -9,7 +9,13 @@ class PraiseTreadController < ApplicationController
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
@activity = false
if request.get?
if !params[:user_activity_id].nil? && !params[:type].nil?
@user_activity_id = params[:user_activity_id]
@type = params[:type]
@activity = true
end
@obj_id = params[:obj_id]
@obj_type = params[:obj_type]
#@horizontal = params[:horizontal].downcase == "false" ? false:true
@ -17,13 +23,12 @@ class PraiseTreadController < ApplicationController
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
end
def praise_minus
@obj = nil
@activity = false
if request.get?
#@obj = params[:obj] # 传的是对象最后变成id了
@obj_id = params[:obj_id]
@ -43,8 +48,11 @@ class PraiseTreadController < ApplicationController
end
#@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]
if !params[:user_activity_id].nil? && !params[:type].nil?
@user_activity_id = params[:user_activity_id]
@type = params[:type]
@activity = true
end
respond_to do |format|
format.js
end

View File

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

View File

@ -1,4 +1,4 @@
<% if @user_activity_id %>
<% if @activity %>
<% if @type.to_s == 'activity' %>
$('#praise_count_<%=@user_activity_id %>').html('<%= j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"activity"})%>');
<% else %>

View File

@ -2,7 +2,7 @@
$('#praise_tread_<%= @obj.id %>').html('<%= j(
render :partial => "/memos/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id,:horizontal => @horizontal}
)%>');
<% elsif @user_activity_id %>
<% elsif @activity %>
<% if @type.to_s == 'activity' %>
$('#praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"activity"})%>');
<% else %>